gpt4 book ai didi

javascript - 将一些 json 数据推送到 Node.js 中的空数组

转载 作者:行者123 更新时间:2023-12-02 17:56:05 25 4
gpt4 key购买 nike

我有以下数据

myArray = [ { Tests: [ [Object] ],
_id: '52bd60d72270a398d3f87302',
browser: [ 'FF' ],
id: '71',
mode: 'weekly',
os: 'VM-WIN7-64',
server: '172.16.2.120' },
{ Tests: [ [Object], [Object] ],
_id: '52c247f1cf0060b8cce84b42',
browser: [ 'FF' ],
id: '45',
mode: 'daily',
os: 'VM-WIN7-64',
server: '172.16.2.120' },
{ _id: '52ca2b0dafcec877d925d111',
Tests: [ [Object], [Object], [Object] ],
browser: [ 'FF', 'IE' ],
id: '37',
mode: 'daily',
os: 'VM-WIN7-32',
server: '172.16.2.120' } ];

我只想将其中一些值推送到 newArray,如下所示。怎么可能呢?我正在使用 Node.js。

newArray = [{    
browser: [ 'FF' ],
id: '71'},
{
browser: [ 'FF' ],
id: '45'},
{
browser: [ 'FF', 'IE' ],
id: '37'},
];

最佳答案

类似这样的事情

var newArray = myArray.map(function(obj) {
return {browser : obj.browser, id : obj.id}
});

FIDDLE

关于javascript - 将一些 json 数据推送到 Node.js 中的空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20943788/

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