/    Sign up×
Community /Pin to ProfileBookmark

Making a string into an Array

Hello,

I’ve got a problem thats got me pretty stumped. I’m adapting a menu script (which I’ll be getting the paid version for if this works!) to work with a shopping cart system. The menu script (COOLjsMenu) builds an array with code that looks like this…

[CODE]
var MENU_ITEMS = [
{pos:[10,10], itemoff:[0,99], leveloff:[21,0], style:STYLE, size:[22,100]},
{code:”Item 1″,
sub:[
{code:”SubItem 1″,
sub:[
{code:”SubSubItem 1″},
{code:”SubSubItem 2″},
{code:”SubSubItem 3″}
]
},
{code:”SubItem 2″,
sub:[
{code:”SubSubItem 1″},
{code:”SubSubItem 2″},
{code:”SubSubItem 3″}
]
},
]
},
{code:”Item 2″,
sub:[
{code:”SubItem 1″,
sub:[
{code:”SubSubItem 1″},
{code:”SubSubItem 2″},
{code:”SubSubItem 3″}
]
},
{code:”SubItem 2″,},
{code:”SubItem 3″,
sub:[
{code:”SubSubItem 1″},
]
}
]
},

];
[/CODE]

The shopping cart system dumps an array which I’ve written a script for that constructs the code into a string var (called menucode) that has the same formatting as above.

If I cut and paste the output from my code into the script to use then it works no problem, but I need it to take the string I’ve built it into and use that.

The issue is that using “var MENU_ITEMS = menucode” doesn’t make MENU_ITEMS as an array, it just makes another string.

How do I get it so that I can make MENU_ITEMS an array built from the string menucode?

Thanks for any help you can give me on this one guys,

Regards,

Leonard

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@TJ111Dec 11.2007 — Well, however you have the string seperated, just use loops and str.split. For example.
<i>
</i>menucode = "Home~index.html::Products~products.html::Company~company.html";

var arr = menucode.split("::");
for (var i=o;i&lt;arr.length;i++) {
var tmp = arr[i].split("~");
menucode[i][0] = tmp[0];
menucode[i][1] = tmp[1];
}
//rinse and repeat as many times as you need
Copy linkTweet thisAlerts:
@JMRKERDec 11.2007 — TJ111 - question:

First, is menucode (the string) meant to be replaced by the multi-dimension array named menucode?

Should not the array have a different name?

Second, if the array is created from the string, how is the array initialize?

var menuArray = [[]];

or

var menuArray = new Array( new Array() );

or

menuArray = [][];

Neat concept, I just don't understand it all. ?
Copy linkTweet thisAlerts:
@TJ111Dec 11.2007 — Oh thanks for pointing that out. I've been working with PHP today so I forget you have to initialize the array. Also the array should not be menucode, it should be MENU_ITEMS. I'm not performing some javascript magic, lol, just had a few oversights, so your right to be confused.
<i>
</i>var menucode = "Home~index.html::Products~products.html::Company~company.html";
var MENU_ITEMS = new Array();
var arr = menucode.split("::");

for (var i=o;i&lt;arr.length;i++) {
var tmp = arr[i].split("~");
MENU_ITEMS[i][0] = tmp[0];
MENU_ITEMSe[i][1] = tmp[1];
//you could use more loops here for however deep you want the menu to be
}

Copy linkTweet thisAlerts:
@JMRKERDec 11.2007 — TJ111 - more questions.

In your post, you initialize the for (var i=o; ...

I think you meant for (var i=0; ...

But, I created this small variation of your script for testing and get an error

that says "menuArray[i] has no properties"



Any idea what needs to be changed?



[code=php]
<html>
<head>
<title>Menu Array</title>
<script type="text/javascript">

var menucode = "Home~index.html::Products~products.html::Company~company.html";
var menuArray = new Array();

function SplitStr(str) {
var arr = str.split("::");
for (var i=0;i<arr.length;i++) {
var tmp = arr[i].split("~");
menuArray[i][0] = tmp[0];
menuArray[i][1] = tmp[1];
}
}
//rinse and repeat as many times as you need

function ShowArray() {
var str = '';
for (var i=0;i<menuArray.length;i++) {
str += menuArray[i][0];
str += 'n'+menuArray[i][1];
}
alert(str);
}
</script>
</head>
<body>
<button onClick="SplitStr(menucode)">Split String</button><br />
<button onClick="ShowArray()">Show Array</button><br />

</body>
</html>
[/code]

Sorry to be a bother on someone's post. :o
Copy linkTweet thisAlerts:
@TJ111Dec 11.2007 — After taking a look at it, it seems like you have initialize each instance of the second dimension of the array individually. Using your script, the following worked fine (made it inline so it just runs on load).
<i>
</i>var menucode = "Home~index.html::Products~products.html::Company~company.html";
var menuArray = new Array();


var arr = menucode.split("::");
for (var i=0;i&lt;arr.length;i++) {
menuArray[i] = new Array();

<i> </i>var tmp = arr[i].split("~");
<i> </i>menuArray[i][0] = tmp[0];
<i> </i>menuArray[i][1] = tmp[1];
}
alert(menuArray[1][1])



var str = '';
for (var i=0;i&lt;menuArray.length;i++) {
str += menuArray[i][0];
str += ' = '+menuArray[i][1]+ "n";
}
alert(str);
Copy linkTweet thisAlerts:
@Leonard_BauthorDec 11.2007 — Thanks for your help so far guys, I might have to rewrite my script to make the proper array from the outset.

Got my head around what's going on a bit more now. At the moment the MENU_ITEMS var I posted originally is a literal array. I'm not that experienced so I didn't realise it was actually an array, so I've been building menucode as a string that is the code that would build a literal array.

Its not building the literal array though and I don't know how to tell it to do so. I've tried all sorts of variations on

var MENU_ITEMS = menucode ;

which I really need to give me the value thats in menucode in a way that MENU_ITEMS will make it a literal array.

Sorry if thats not as well explained as it could have been, I've been working on that all day and my brain is a little fried!

Regards,

Leonard
Copy linkTweet thisAlerts:
@TJ111Dec 11.2007 — Can you post an example the string "menucode"?
Copy linkTweet thisAlerts:
@JMRKERDec 11.2007 — TJ111:
After taking a look at it, it seems like you have initialize each instance of the second dimension of the array individually. [/QUOTE]

Thank you. Works as advertised. I was just following your original post.


At least I now know I not going crazy as fast as I thought I was. :rolleyes:

Leonard_B:

Thanks for the original post.
Copy linkTweet thisAlerts:
@Leonard_BauthorDec 12.2007 — Can you post an example the string "menucode"?[/QUOTE]

This is what its generating for the menu code...

[CODE][ {pos:[10,10], itemoff:[21,0], leveloff:[0,99], style:STYLE, size:[22,100]},{code:"Amplification", "url":"/cgi_data/ss000001.pl?SECTIONID=Amplification%2ehtml&NOLOGIN=1",sub:[{},{code:"Bass Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Trace Elliot", "url":"/cgi_data/ss000001.pl?SECTIONID=Trace%5fElliot%5fBass%5fAmps%2ehtml&NOLOGIN=1"},{code:"Line 6", "url":"/cgi_data/ss000001.pl?SECTIONID=Line%5f6%5fBass%5fAmp%2ehtml&NOLOGIN=1"},{code:"Mark Bass", "url":"/cgi_data/ss000001.pl?SECTIONID=Mark%5fBass%2ehtml&NOLOGIN=1"},{code:"Roland", "url":"/cgi_data/ss000001.pl?SECTIONID=Roland%5fbass%5famps%2ehtml&NOLOGIN=1"},],},{code:"Acoustic Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Acoustic%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Mark Bass", "url":"/cgi_data/ss000001.pl?SECTIONID=Mark%5fBass%5fAcoustic%2ehtml&NOLOGIN=1"},],},{code:"Electric Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Peavey", "url":"/cgi_data/ss000001.pl?SECTIONID=Peavey%5fGuitar%5fAmplifiers%2ehtml&NOLOGIN=1"},{code:"Line 6", "url":"/cgi_data/ss000001.pl?SECTIONID=Line%5f6%2ehtml&NOLOGIN=1"},{code:"Roland", "url":"/cgi_data/ss000001.pl?SECTIONID=Roland%5fguitar%5famps%2ehtml&NOLOGIN=1"},{code:"Vox", "url":"/cgi_data/ss000001.pl?SECTIONID=Vox%5fguitar%5famps%2ehtml&NOLOGIN=1"},],},],},{code:"Guitars", "url":"/cgi_data/ss000001.pl?SECTIONID=Guitars%2ehtml&NOLOGIN=1",sub:[{},{code:"Acoustic", "url":"/cgi_data/ss000001.pl?SECTIONID=Acoustic%2ehtml&NOLOGIN=1",sub:[{},{code:"12-String Acoustics", "url":"/cgi_data/ss000001.pl?SECTIONID=12%2dString%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Beginners Acoustic", "url":"/cgi_data/ss000001.pl?SECTIONID=Beginners%5fAcoustic%2ehtml&NOLOGIN=1"},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5fAcoustic%5fGuitars%2ehtml&NOLOGIN=1"},{code:"Left-Handed", "url":"/cgi_data/ss000001.pl?SECTIONID=Left%2dHanded%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=Dean%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Washburn", "url":"/cgi_data/ss000001.pl?SECTIONID=Washburn%5facoustic%5fguitars%2ehtml&NOLOGIN=1"},],},{code:"Bass Guitars", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitars%2ehtml&NOLOGIN=1",sub:[{},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5fBass%5fGuitars%2ehtml&NOLOGIN=1"},{code:"Starter Packs", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fStarter%5fPacks%2ehtml&NOLOGIN=1"},],},{code:"Classical", "url":"/cgi_data/ss000001.pl?SECTIONID=Classical%2ehtml&NOLOGIN=1",sub:[{},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=Dean%5fclassicals%2ehtml&NOLOGIN=1"},],},{code:"Electric", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%2ehtml&NOLOGIN=1",sub:[{},{code:"Starter Packs", "url":"/cgi_data/ss000001.pl?SECTIONID=Starter%5fPacks%2ehtml&NOLOGIN=1"},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=dean%5felectrics%2ehtml&NOLOGIN=1"},{code:"ESP Ltd.", "url":"/cgi_data/ss000001.pl?SECTIONID=ESP%5fLtd%5fEL%2ehtml&NOLOGIN=1"},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5felectric%5fguitars%2ehtml&NOLOGIN=1"},{code:"Peavey", "url":"/cgi_data/ss000001.pl?SECTIONID=Peavey%2ehtml&NOLOGIN=1"},{code:"Lag", "url":"/cgi_data/ss000001.pl?SECTIONID=Lag%5felectric%5fguitars%2ehtml&NOLOGIN=1"},{code:"Yamaha", "url":"/cgi_data/ss000001.pl?SECTIONID=Yamaha%5fElectric%5fGuitars%2ehtml&NOLOGIN=1"},],},],},{code:"Effects", "url":"/cgi_data/ss000001.pl?SECTIONID=Effects%2ehtml&NOLOGIN=1",sub:[{},{code:"Bass Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fEffects%2ehtml&NOLOGIN=1",sub:[{},],},{code:"Electric Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fEffects%2ehtml&NOLOGIN=1",sub:[{},{code:"Multi-Effects", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fMulti%5fEffects%2ehtml&NOLOGIN=1"},{code:"Stomp Boxes", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fStomp%5fBoxes%2ehtml&NOLOGIN=1"},],},],},{code:"Drums", "url":"/cgi_data/ss000001.pl?SECTIONID=Drum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Electronic Kits", "url":"/cgi_data/ss000001.pl?SECTIONID=Electronic%5fDrum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Yamaha", "url":"/cgi_data/ss000001.pl?SECTIONID=Yamaha%5fElectronic%5fKits%2ehtml&NOLOGIN=1"},],},{code:"Starter Kits", "url":"/cgi_data/ss000001.pl?SECTIONID=Starter%5fDrum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Ludwig", "url":"/cgi_data/ss000001.pl?SECTIONID=Ludwig%5fDrum%5fKits%2ehtml&NOLOGIN=1"},],},],},{code:"Audio Software", "url":"/cgi_data/ss000001.pl?SECTIONID=Audio%5fSoftware%2ehtml&NOLOGIN=1",sub:[{},{code:"IK Multimedia", "url":"/cgi_data/ss000001.pl?SECTIONID=IK%5fMultimedia%2ehtml&NOLOGIN=1",sub:[{},],},],},]; [/CODE]

Apologies that the formatting isn't tidied as it wasn't intended to be seen when being generated! As I mentioned before, it works perfectly if I copy and paste that into the code, just not if I try and make it from the menucode variable.

Leonard_B:

Thanks for the original post.[/QUOTE]


No problem, I've picked up some interesting stuff from you guys! Thanks for replying
Copy linkTweet thisAlerts:
@JMRKERDec 12.2007 — Sorry for the confusion, but what exactly do you want to do?

My assumption is that the 'Code:' in the last post is being sent from somewhere.

Then you want to:

1. Format it like post #1

or

2. Create a menu display from the string by translating it to an array

or

3. Create a multi-dimension array from the string

It's not clear to me what the final goal is. ?
Copy linkTweet thisAlerts:
@Leonard_BauthorDec 12.2007 — Sorry, my explanations haven't been majorley clear, my brains been fried by this one.

The answer to your questions is number 3.

The code I posted in my previous post is the result of what my script is giving me once its processed the output arrays that contain the site structure from the cart system. It does have the same formatting as the code example I posted in the first post, its just my generated code doesn't have all the line breaks and visual formatting.

This code is a literal array so the below code will make a multidimensional array from it.

[CODE]var MENU_ITEMS = [ {pos:[10,10], itemoff:[21,0], leveloff:[0,99], style:STYLE, size:[22,100]},{code:"Amplification", "url":"/cgi_data/ss000001.pl?SECTIONID=Amplification%2ehtml&NOLOGIN=1",sub:[{},{code:"Bass Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Trace Elliot", "url":"/cgi_data/ss000001.pl?SECTIONID=Trace%5fElliot%5fBass%5fAmps%2ehtml&NOLOGIN=1"},{code:"Line 6", "url":"/cgi_data/ss000001.pl?SECTIONID=Line%5f6%5fBass%5fAmp%2ehtml&NOLOGIN=1"},{code:"Mark Bass", "url":"/cgi_data/ss000001.pl?SECTIONID=Mark%5fBass%2ehtml&NOLOGIN=1"},{code:"Roland", "url":"/cgi_data/ss000001.pl?SECTIONID=Roland%5fbass%5famps%2ehtml&NOLOGIN=1"}]},{code:"Acoustic Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Acoustic%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Mark Bass", "url":"/cgi_data/ss000001.pl?SECTIONID=Mark%5fBass%5fAcoustic%2ehtml&NOLOGIN=1"}]},{code:"Electric Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Peavey", "url":"/cgi_data/ss000001.pl?SECTIONID=Peavey%5fGuitar%5fAmplifiers%2ehtml&NOLOGIN=1"},{code:"Line 6", "url":"/cgi_data/ss000001.pl?SECTIONID=Line%5f6%2ehtml&NOLOGIN=1"},{code:"Roland", "url":"/cgi_data/ss000001.pl?SECTIONID=Roland%5fguitar%5famps%2ehtml&NOLOGIN=1"},{code:"Vox", "url":"/cgi_data/ss000001.pl?SECTIONID=Vox%5fguitar%5famps%2ehtml&NOLOGIN=1"}]}]},{code:"Guitars", "url":"/cgi_data/ss000001.pl?SECTIONID=Guitars%2ehtml&NOLOGIN=1",sub:[{},{code:"Acoustic", "url":"/cgi_data/ss000001.pl?SECTIONID=Acoustic%2ehtml&NOLOGIN=1",sub:[{},{code:"12-String Acoustics", "url":"/cgi_data/ss000001.pl?SECTIONID=12%2dString%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Beginners Acoustic", "url":"/cgi_data/ss000001.pl?SECTIONID=Beginners%5fAcoustic%2ehtml&NOLOGIN=1"},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5fAcoustic%5fGuitars%2ehtml&NOLOGIN=1"},{code:"Left-Handed", "url":"/cgi_data/ss000001.pl?SECTIONID=Left%2dHanded%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=Dean%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Washburn", "url":"/cgi_data/ss000001.pl?SECTIONID=Washburn%5facoustic%5fguitars%2ehtml&NOLOGIN=1"}]},{code:"Bass Guitars", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitars%2ehtml&NOLOGIN=1",sub:[{},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5fBass%5fGuitars%2ehtml&NOLOGIN=1"},{code:"Starter Packs", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fStarter%5fPacks%2ehtml&NOLOGIN=1"}]},{code:"Classical", "url":"/cgi_data/ss000001.pl?SECTIONID=Classical%2ehtml&NOLOGIN=1",sub:[{},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=Dean%5fclassicals%2ehtml&NOLOGIN=1"}]},{code:"Electric", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%2ehtml&NOLOGIN=1",sub:[{},{code:"Starter Packs", "url":"/cgi_data/ss000001.pl?SECTIONID=Starter%5fPacks%2ehtml&NOLOGIN=1"},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=dean%5felectrics%2ehtml&NOLOGIN=1"},{code:"ESP Ltd.", "url":"/cgi_data/ss000001.pl?SECTIONID=ESP%5fLtd%5fEL%2ehtml&NOLOGIN=1"},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5felectric%5fguitars%2ehtml&NOLOGIN=1"},{code:"Peavey", "url":"/cgi_data/ss000001.pl?SECTIONID=Peavey%2ehtml&NOLOGIN=1"},{code:"Lag", "url":"/cgi_data/ss000001.pl?SECTIONID=Lag%5felectric%5fguitars%2ehtml&NOLOGIN=1"},{code:"Yamaha", "url":"/cgi_data/ss000001.pl?SECTIONID=Yamaha%5fElectric%5fGuitars%2ehtml&NOLOGIN=1"}]}]},{code:"Effects", "url":"/cgi_data/ss000001.pl?SECTIONID=Effects%2ehtml&NOLOGIN=1",sub:[{},{code:"Bass Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fEffects%2ehtml&NOLOGIN=1",sub:[{}]},{code:"Electric Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fEffects%2ehtml&NOLOGIN=1",sub:[{},{code:"Multi-Effects", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fMulti%5fEffects%2ehtml&NOLOGIN=1"},{code:"Stomp Boxes", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fStomp%5fBoxes%2ehtml&NOLOGIN=1"}]}]},{code:"Drums", "url":"/cgi_data/ss000001.pl?SECTIONID=Drum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Electronic Kits", "url":"/cgi_data/ss000001.pl?SECTIONID=Electronic%5fDrum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Yamaha", "url":"/cgi_data/ss000001.pl?SECTIONID=Yamaha%5fElectronic%5fKits%2ehtml&NOLOGIN=1"}]},{code:"Starter Kits", "url":"/cgi_data/ss000001.pl?SECTIONID=Starter%5fDrum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Ludwig", "url":"/cgi_data/ss000001.pl?SECTIONID=Ludwig%5fDrum%5fKits%2ehtml&NOLOGIN=1"}]}]},{code:"Audio Software", "url":"/cgi_data/ss000001.pl?SECTIONID=Audio%5fSoftware%2ehtml&NOLOGIN=1",sub:[{},{code:"IK Multimedia", "url":"/cgi_data/ss000001.pl?SECTIONID=IK%5fMultimedia%2ehtml&NOLOGIN=1",sub:[{}]}]}][/CODE]

This works no problem, but the way I have been trying to build it is...

[CODE]menucode = '[ {pos:[10,10], itemoff:[21,0], leveloff:[0,99], style:STYLE, size:[22,100]},{code:"Am...' etc

var MENU_ITEMS = menucode ;[/CODE]


menucode is built by my script as a string (in a little more complicated form then above ? ). When I want to put that string into MENU_ITEMS I need it to be turned into a literal array, but it doesn't process the string into a literal array, just make MENU_ITEMS a copy of menucode. This is the last thing thats stopping my script from working! Exhausted my ideas to fix it!

Any idea how to make it process the string into a literal array?
Copy linkTweet thisAlerts:
@TJ111Dec 12.2007 — What you want to use is [url=http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#Object_Literals]javascript object notation[/url]. "Literal" arrays (or hashes) don't exist in javascript, you have to use objects.
Copy linkTweet thisAlerts:
@Leonard_BauthorDec 12.2007 — I've been reading some misleading sites then I think. The code does generate something that can be read like an array but now if its not then I'm a little lost.

My next question is, is there a simple way to make my menucode string into the object?
Copy linkTweet thisAlerts:
@TJ111Dec 12.2007 — Yeah, just remove the single quotes around it as well as the []brackets from the outside.

Objects:
<i>
</i>var menucode = {
name : "Home",
pos : [10,10],
url : "http://whaterver.com"
}
alert(menucode.name) //"Home"
alert(menucode['pos']) //"Array"
alert(menucode['pos'][0]) //Should alert "10" i think
alert(menucode[2]) //"http://whatever.com"
×

Success!

Help @Leonard_B spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...