gpt4 book ai didi

javascript - 如何检查数组是否有键:value or not?

转载 作者:行者123 更新时间:2023-11-28 21:22:27 25 4
gpt4 key购买 nike

  var people =[{title:'Alan', hasChild:true},
{title:'Alice', hasDetail:true},
{title:'Amos', header'A'},
{title:'Alonzo'},
{title:'Brad'},
{title:'Brent'},
{title:'Billy'},
{title:'Brenda'},
{title:'Callie'},
{title:'Cassie'},
{title:'Chris'}];

我想检查这个数组,它是否包含键、值header:value。我想检查每个元素。

最佳答案

应该这样做:

for (var i = 0, c = people.length;i < c;i++) {
if (people[i].header) {
// yay
// not sure wether you want to check the value as well
// but if that is the case, you'd do this
if (people[i].header == 'A') {
// do some more stuff
}
} else {
// nay
}
}

关于javascript - 如何检查数组是否有键:value or not?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5935496/

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