使用javascript / es6,如何编写单行代码并返回一个布尔值,该布尔值指定data是否包含theId == 3的条目:

let data = [{"name":"Tom",address:"Here","theId":"1"},{"name":"Neve",address:"There","theId":"2"}]


如果我仅限于以此方式组织data

最佳答案

您可以使用some()和ES6箭头功能。



let data = [{"name":"Tom",address:"Here","theId":"1"},{"name":"Neve",address:"There","theId":"2"}]
var check = data.some(arr => arr.theId == 3);
console.log(check)

09-07 16:24