2

I'm trying to build an array to create a menu system where each index has 2 objects, a name and a subarray of Strings.

I tried something like this:

var menus = [];
menus.push({title:"Aztec", mySubArray:{"String1", "String2","String3"} });

but that doesnt seem to be the right syntax. any ideas?

thanks

2 Answers 2

5

You have a syntax error, mySubArray has to be an array []

var menus = [];
menus.push({title:"Aztec", mySubArray:["String1", "String2","String3"] });
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, for some reason I thought that wouldn't work and skipped it over. thanks!
2

mySubArray is not a valid object, because it's missing property names, which makes it an array. You can fix this by either making mySubArray an array:

mySubArray:["String1", "String2","String3"]

or by adding property names to make it an actual object:

mySubArray:{1: "String1", 2: "String2",3: "String3"}

The issue isn't with the fact that it's a "sub array" being pushed, only with the syntax of the actual mySubArray value.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.