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
1 Answer
Reset to default 5You 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
版权声明:本文标题:Javascript array push subarray - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742214996a2434405.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论