Javascript 如何从对象数组中提取元素以实现对象?
假设我有一个由四个对象组成的数组:Javascript 如何从对象数组中提取元素以实现对象?,javascript,Javascript,假设我有一个由四个对象组成的数组: var jsObjects = [ {id: 1, cost: 10, comment: 'test'}, {id: 4, cost: 100, comment: 'test'}, {id: 5, cost: 110, comment: 'test'}, {id: 7, cost: 120, comment: 'test'} ]; 如果“cost”的值大于100,我将从该表中提取键、'id'和'cost'的值,以获得如下对象:
var jsObjects = [
{id: 1, cost: 10, comment: 'test'},
{id: 4, cost: 100, comment: 'test'},
{id: 5, cost: 110, comment: 'test'},
{id: 7, cost: 120, comment: 'test'}
];
如果“cost”的值大于100,我将从该表中提取键、'id'和'cost'的值,以获得如下对象:
new object = {4:100, 5:110, 7:120}
如果您有可以帮助我的解决方案。您尝试了什么。您的输出也是无效的对象。@mplungjan,很抱歉,我更改了输出新对象={4:100,5:110,7:120}