theDickChuck
theDickChuck

Reputation: 81

javascript error array creation

this is the code

var xyzTris = [[[0,-3,4],[-2,0,4],[2,0,4]]];
console.log("zero: ",rdfTris);
var scrTris = [[[]]];
console.log("first: ",scrTris);
var rdfTris = [[[]]];
console.log("second: ",rdfTris);

What's strange is, the console out shows:

zero: undefined
first: Array [[[]]]
second: Array [[[0, -3, 4]]]

Anybody get why the rdfTris array is mal-defined?

I've tried all sorts of rearrangements, the parser just seems confused by rdfTris and xyzTris. I discovered this downstream when I was getting some weird array elements not defined later in the code. Stripped all that away to get to this.

Upvotes: 0

Views: 63

Answers (1)

pseudological
pseudological

Reputation: 65

You are logging the value of rdfTris on line 2, but you assign a value to rdfTris on line 5.

var xyzTris = [[[0,-3,4],[-2,0,4],[2,0,4]]];
console.log("zero: ",xyzTris);
var scrTris = [[[]]];
console.log("first: ",scrTris);
var rdfTris = [[[]]];
console.log("second: ",rdfTris);

The above should work as expected.

Upvotes: 1

Related Questions