gpt4 book ai didi

javascript - 将对象数组插入数组的最佳方法是什么

转载 作者:行者123 更新时间:2023-12-04 09:14:00 24 4
gpt4 key购买 nike

关闭。这个问题需要details or clarity .它目前不接受答案。












想改善这个问题吗?通过 editing this post 添加详细信息并澄清问题.

去年关闭。




Improve this question




这是要推送到数组的对象数组

  [{"a":11,"b":21},{"a":31,"b":41},{"a":10,"b":20}]
如何从上面实现下面的这个数组
"array": [
[
[
11,
21
],
[
31,
41
],

[
10,
20
]
]
]

最佳答案

使用 Array.prototype.map()

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.



var array1 = [{"a":11,"b":21},{"a":31,"b":41},{"a":10,"b":20}];

var array2 = [array1.map(item=>[item.a, item.b])];

console.log(array2);

关于javascript - 将对象数组插入数组的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63302256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com