0

I have an array with objects, which are props on a react component

this.props.items = [
    {make: Audi, model: A1, premiere: true},
    {make: BMW, model: X1, premiere: false},
    {make: Merc, model: C1, premiere: false}
]

I want to grab the details of the first object because it is

'premiere: true'

Which I can do like so:

this.props.items.map(x => x.premiere);

How can I grab all of the objects remaining keys and values and store them in them in state of the component?

{make: Audi, model: A1, premiere: true}
js-learner
  • 457
  • 2
  • 9
  • 26
  • Through load dash lib : let filteredTimes = _.map(items, function(o) { if (o.premiere == true) return o; }); – abhay Oct 23 '20 at 11:08

2 Answers2

2

Use Array.prototype.filter instead of Array.prototype.map

netizen
  • 1,028
  • 7
  • 19
2

change this.props.items.map(x => x.premiere); to this.props.items.filter(x => x.premiere);

Quang Thái
  • 649
  • 5
  • 17