Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript arrays, how to change this array structure

I have 3 arrays in javascript. I'd like to combine them all into 1 var, but name each item (like PHP's associate array). So the first item is red, second is green, third is blue. And then how do I call each item separately after?

[[2, 1], [4, 1], [10, 1], [19, 1]],
[[3, 1], [14, 1], [18, 1], [19, 1]],
[[7, 1], [6, 1], [8, 1], [17, 1]]
like image 660
sameold Avatar asked Dec 27 '22 14:12

sameold


1 Answers

Do you mean something like this?

var combined = {
    red: [[2, 1], [4, 1], [10, 1], [19, 1]],
    green: [[3, 1], [14, 1], [18, 1], [19, 1]],
    blue: [[7, 1], [6, 1], [8, 1], [17, 1]]
};

Then you can access the arrays as combined.red, combined.green, and combined.blue.

like image 114
cdhowie Avatar answered Jan 06 '23 05:01

cdhowie