-1

Suppose there is an Array that has some objects like below

[{name:"Bruce wayne" age:42 DOA:true},{name: "Dick grayson" age:28 DOA:true},{name:"Jason todd" age:24 DOA:false}]

and I want to get a new Array with Objects which DOA is true (bruce and dick).

Is there any good API or something to do this?

your help is going to be appreciated Thx!

geo
  • 821
  • 1
  • 8
  • 15
  • 3
    [`Array#filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) – VLAZ Jul 29 '21 at 16:05

1 Answers1

1

You can simply use Array.prototype.filter:

const data = [{
  name: "Bruce wayne",
  age: 42,
  DOA: true
}, {
  name: "Dick grayson",
  age: 28,
  DOA: true
}, {
  name: "Jason todd",
  age: 24,
  DOA: false
}];

console.log(data.filter(obj => obj.DOA));

Mind that your JSON was also invalid.

Kelvin Schoofs
  • 8,323
  • 1
  • 12
  • 31