gpt4 book ai didi

javascript - 返回 json 对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:53:32 26 4
gpt4 key购买 nike

我有一个像这样的对象数组

 objArray =   [{"color":"red", "width":5, "price":10},
{"color":"green", "width":4, "price":8},
{"color":"red", "width":7, "price":11}]

如何在 javascript 或 jquery 中返回颜色为红色的对象数组

最佳答案

 var objArray =   [{"color":"red", "width":5, "price":10},
{"color":"green", "width":4, "price":8},
{"color":"red", "width":7, "price":11}]

var tmp = []

$.each(objArray,function(i,val){
if(val.color == 'red')
{
tmp.push(objArray[i]);
}
});

console.log(tmp);

关于javascript - 返回 json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7211535/

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