admin管理员组

文章数量:1336380

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

I want it to be:

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

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

I want it to be:

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

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jul 23, 2013 at 23:48 mike628mike628 49.4k19 gold badges45 silver badges57 bronze badges 1
  • 4 mdn array docs – aaronman Commented Jul 23, 2013 at 23:51
Add a ment  | 

1 Answer 1

Reset to default 5

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].

本文标签: Javascript array push subarrayStack Overflow