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

array and subarray

P: n/a
if I have
array-n-01=[0,1,2,3, 4,5, 6, 7,8,9,10]
array-n-02=[0,4,6,7]

want change in one array03 so:
array03[0]=[1.2.3]
array03[4]=[5]
array03[6]=[]
array03[7]=[8,9,10]

the sub elements in array03 are the
Aug 31 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
artev wrote:
if I have
array-n-01=[0,1,2,3, 4,5, 6, 7,8,9,10]
The hyphen '-' is a punctuator in JavaScript and can't be used in an
identifier (such as a variable name). You might like to swap it for an
underscore. I think you mean that the numbers are actually the values
of the array elements, i.e.

var array_n_01 = [ '0,1,2,3', '4,5', '6', '7,8,9,10' ];

array-n-02=[0,4,6,7]
Will the order here *always* be the same as in array_n_01? If so, this
second array isn't needed. Otherwise, an example with it out of order
would have been better.

want change in one array03 so:
array03[0]=[1.2.3]
array03[4]=[5]
array03[6]=[]
array03[7]=[8,9,10]
Assuming the order is as per array_n_01:

var array_n_01 = ['0,1,2,3', '4,5', '6', '7,8,9,10'];
var array03 = [];

var x;
for (var i=0, len=array_n_01.length; i<len; i++){
x = array_n_01[i].split(',');
array03[x.shift()] = x.join(',');
}
Assuming the order is as per array_n_02:

var array_n_02 = [0,6,7,4];

for (var i=0, len=array_n_02.length; i<len; i++){
array03[array_n_02[i]] = [];
}
for (var p in array_n_01){
t = array_n_01[p].split(',');
array03[t.shift()] = t.join(',');
}
--
Rob

Sep 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.