gpt4 book ai didi

javascript - 如何从对象数组中获取元素?

转载 作者:行者123 更新时间:2023-12-02 18:11:43 26 4
gpt4 key购买 nike

var fkTableArr1d = new Array();

fkTableArr1d = _.map(fkTableArr2d, function(list, iterator, context) {
return { "id " : list[0], "label " : list[1] };
});

fkTableArr1d 变为:[对象,对象,对象]

1 个对象是一个对象 {id : "5", label : "fuel"}

现在我应该如何获取带有标签 fuel 的元素的 ID?

下面的方法不起作用:

console.log(fkTableArr1d['fuel']);

最佳答案

看起来您正在寻找 findWhere() :

Looks through the list and returns the first value that matches all of the key-value pairs listed in properties.

_.findWhere(fkTableArr1d, {label : "fuel"});

演示:http://jsfiddle.net/38qUE/1/

关于javascript - 如何从对象数组中获取元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19657369/

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