Monday, May 20, 2024
195
rated 0 times [  199] [ 4]  / answers: 1 / hits: 17182  / 13 Years ago, mon, may 9, 2011, 12:00:00

Is it possible to have a jagged array in JavaScript?



Here is the format of the data I want to store in a jagged array:



(key)(value1, value2, value3)


Can I put this in a jagged array?


More From » jagged-arrays

 Answers
8

Yes, you can create that type of array using object or array literal grammar, or object/array methods.



An array of arrays:



// Using array literal grammar
var arr = [[value1, value2, value3], [value1, value2]]

// Creating and pushing to an array
var arr = [];
arr.push([value1, value2, value3]);


An object of arrays:



// Using object literal grammar
var obj = { key: [value1, value2, value3], key2: [value1, value2] }

// Creating object properties using bracket or dot notation
var obj = {};
obj.key = [value1, value2, value3];
obj[key2] = [value1, value2];

[#92328] Saturday, May 7, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
theo

Total Points: 680
Total Questions: 108
Total Answers: 81

Location: Laos
Member since Fri, Sep 11, 2020
4 Years ago
;