[英]get the object which property contains an array as the value using javascript
I have an array containing some objects like this :我有一个包含一些像这样的对象的数组:
var lists = [{
"id": 1,
"status": 1,
"inputs": [],
"outputs": [
""
]
}, {
"id": "",
"status": 1,
"inputs": [
"test",
""
],
"outputs": [
""
]
}, {
"id": "",
"status": 1,
"inputs": [
"",
"test1"
],
"outputs": [
""
]
}, {
"id": "",
"status": 1,
"inputs": [
"gfg",
""
],
"outputs": [
""
]
}];
From this array I want to get all objects in which the inputs
property contains at least one element.从这个数组中,我想获取
inputs
属性至少包含一个元素的所有对象。 How can I do this?我怎样才能做到这一点?
You just need to filter the array and return only items which has length of inputs array greater than zero .您只需要过滤数组并仅返回输入数组长度大于零的项目。 It can be achieved for example like this
例如可以像这样实现
var x=lists.filter(function(x){return x.inputs.length>=1});
Now x is the array that containts only objcets whose input array isnt empty.现在 x 是只包含输入数组不为空的对象的数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.