检查对象的数组有属性

问题描述 投票:0回答:1

我如何检查的财产包括在JS对象的数组?

const array=[
    { name: "A", hasCar: true},
    { name: "B" }
];

// if (array has "hasCar") {
//    do something
// }

我想,如果阵列有qazxsw POI与否。 qazxsw POI不上对象的数组工作。

我应该使用"hasCar"或任何解决方案?

javascript arrays object
1个回答
0
投票

你可以采取array.includes.hasOwnProperty("hasCar")检查。

© www.soinside.com 2019 - 2024. All rights reserved.