jsonArray = jsonArray.filter(item => !item.position.includes(null))
Or
jsonArray = jsonArray.filter(item => item.position[0] !== null && item.position[1] !== null)
You could do something like:
const result = arrayOfObjects.filter((object) => {
return object.position[0] !== null && object.position[1] !== null);
}
We can use a library lodash and using filter method, like this:
var items = _.filter(items, function(item){return item.position});
or
var items = _.filter(items, function(item){return item.position !== null && item.position !== ""});
we can filter out objects which do have position null
Try this code:
const filtered = array.filter(items => items.position[0] != null || items.position[1] != null);
console.log(filtered);
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.