mike628
mike628

Reputation: 49391

Javascript array push subarray

Each newdata[x][0]] looks like this -> [95, 152, 174, 197, 261] but when I do newgooddata.push([newdata[x][0]]) twice (x=0 and 1) I get NEWDATA

I want it to be:

THE STRUCTURE I WANT

I seem to be adding them wrong. Some help , with an explanation?

Upvotes: 3

Views: 10617

Answers (1)

Caleb
Caleb

Reputation: 1088

You are putting newdata[x][0] into an array before pushing.

newgooddata.push([newdata[x][0]])  // bad

newgooddata.push(newdata[x][0])    // good

The extra [] around newdata[x][0] creates a new array containing one element: newdata[x][0].

Upvotes: 5

Related Questions