/    Sign up×
Community /Pin to ProfileBookmark

2 dimentional arrays

Hi!

I wanted to know how to do multi arrays in js which looks like

[code]element[1][name]
element[1][value]
[/code]

Could anyone tell me how can I implement this in js?

Regards,
Marcin

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangJun 02.2007 — 
I wanted to know how to do multi arrays in js which looks like element[1][name]
element[1][value]
...

[/QUOTE]
Fill, create?
Copy linkTweet thisAlerts:
@marcin201authorJun 02.2007 — Fill, create?[/quote]

I wanna know how to create something like that, filling is easy..
Copy linkTweet thisAlerts:
@rootJun 02.2007 — You can either...
element[i] = new Object;
element[i].name = 'A name';
element[i].value = 1234;
or<i>
</i>element[i] = new Array;
element[i]['name'] = 'A name';
element[i]['value'] = 1234;
orelement[i] = {name:'A name',value:1234}Take your pick, shovel or fork...
Copy linkTweet thisAlerts:
@marcin201authorJun 03.2007 — Thanks a lot, [b].[/b]!



I have one more question: how can I print or whatever (innerHTML maybe) all values from multi array like that:

<i>
</i>element1[0].name = 'Height';
element1[0].value = '40px';

element2[0].name = 'Height';
element2[0].value = '50px';

element2[1].name = 'Width';
element2[1].value = '50px';

element3[0].name = 'Border';
element3[0].value = '1px solid #000';

element3[1].name = 'Margin';
element3[1].value = '2px';

etc.. ?.

How can I print values only from array named element3 and all from array named element3[1] ?
Copy linkTweet thisAlerts:
@JMRKERJun 03.2007 — Try variations of this (added to the previous code):
[code=php]
<body>
<script type="text/javascript">
i = 0; document.writeln(element[i].name+' : '+element[i].value+'<p />');
i = 1; document.writeln(element[i].name+' : '+element[i].value+'<p />');
i = 2; document.writeln(element[i].name+' : '+element[i].value+'<p /><hr><p />');

for (var i=0; i<element.length; i++) {
document.writeln(element[i].name+' : '+element[i].value+'<br />');
}
document.writeln('<p /><hr><p />');
</script>
</body>
[/code]
×

Success!

Help @marcin201 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 5.5,
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,
)...