By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Grouping Arrays with same initial values

P: 11
Hello,
I have a new question about organizing multidimensional arrays.
I have an array containing several others; my aim is to obtain a new array, which groups together those arrays from the first array that share the same initial value ("00527-00527.tif" in this case).

Here's my code:

[HTML]//BEGIN CODE
startingGroup = new Array(); //starting array
startingGroup[0] = ["00527-00527.tif;00527;Product_1;33;25,13"];
startingGroup[1] = ["00527-00527.tif;00528;Product_2;33;25,13"];
startingGroup[2] = ["01211-01211.tif;00119;Product_3;26;25,06"];

//I want to obtain this
resultingGroup = new Array(); //resulting array
resultingGroup[0] = ["00527-00527.tif;00527;Product_1;33;25,13","00527-00527.tif;00528;Product_2;33;25,13"];
resultingGroup[1] = ["01211-01211.tif;00119;Product_3;26;25,06"];[/HTML]

I wonder if is it possible to do it so

Any help would be mouch appreciated

Thanks
Nov 16 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
You could use a temporary array to store the initial values. How would you determine an initial value? Is it till the semi-colon? Use a regular expression to test if the initial string matches.

Use concat() to combine arrays.
Nov 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.