/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help – Begginer – Problem with matrix

The code just keep giving me 6 or 8 independent of the position i’m trying to access.

[CODE]var valueMatrix = 0;
var matrix = [[0,0],[0,0],[0,0]];
matrix[0,0,0] = 1;
matrix[0,1,0] = 2;
matrix[0,0,1] = 3;
matrix[0,1,1] = 4;
matrix[1,0,0] = 5;
matrix[1,1,0] = 6;
matrix[1,0,1] = 7;
matrix[1,1,1] = 8;

function test()
{
valueMatrix = matrix[0,0,0];
alert(valueMatrix);
}[/CODE]

I dont know how to solve this…

(sorry for my poor english)

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyMay 28.2014 — It looks like you're trying to work with a multi-dimensional array, in which case I believe what you want is:
[CODE]
var valueMatrix = 0;
var matrix = [[[]], [[]], [[]]];
matrix[0][0][0] = 1;
matrix[0][1][0] = 2;
matrix[0][0][1] = 3;
matrix[0][1][1] = 4;
matrix[1][0][0] = 5;
matrix[1][1][0] = 6;
matrix[1][0][1] = 7;
matrix[1][1][1] = 8;

function test() {
valueMatrix = matrix[0][0][0];
console.log(valueMatrix);
}
[/CODE]
Copy linkTweet thisAlerts:
@ZearommauthorMay 31.2014 — Yeah! It worked!

Thanks for the support!
×

Success!

Help @Zearomm 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.10,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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