want to filter an array of objects by array value of a key.
var data = [ { "name": "Jim", "age" : [] }, { "name": "Jerry", "age": [1,2] } ]; var notEmpty = _.filter(data, ['age', null]);
would like to have the output of variable notEmpty
return the object Jerry since the age array is not empty.
如果没有lodash,它将是:
const notEmpty = data.filter(el => el.age.length);
使用香草javascript,这将给您所需的结果:
data.filter(x => x["age"].length > 0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.