[英]Filtering array by only false values of a specific key, value pair
I have a an array of objects that looks something like this:我有一个看起来像这样的对象数组:
[
{id: 1, isValid: true, name: "something1", pdpEnabled: false},
{id: 2, isValid: false, name: "something2", pdpEnabled: false}
]
I am trying to filter out all the objects that contain isValid: false.我正在尝试过滤掉所有包含 isValid: false 的对象。 I am unsure of how to go about this when the objects contain other key value pairs that also contain the value of false for pdpEnabled.
当对象包含也包含 pdpEnabled 的 false 值的其他键值对时,我不确定如何解决这个问题。 Is there a way to filter by a specific key value pair?
有没有办法按特定的键值对过滤?
const newArray=[
{id: 1, isValid: true, name: "something1, pdpEnabled: false"},
{id: 2, isValid: false, name: "something2, pdpEnabled: false}
].filter(item=>item.isValid===true);
Just search for that key for which the value is false (isValid: false), no need to worry about other keys只需搜索值为 false 的那个键(isValid: false),无需担心其他键
const input = [{ id: 1, isValid: true, name: "something1", pdpEnabled: false, }, { id: 2, isValid: false, name: "something2", pdpEnabled: false } ]; const result = input.filter(x =>.x.isValid) console.log(result)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.