4

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]]

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Similarly to PHP's associative arrays, you can also access it like combined["red"], combined["green"], and combined["blue"].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.