score:4

Accepted answer

it seems you need filter.it will return an array of object

let a = [{
  id: 1,
  name: 'new york'
}, {
  id: 2,
  name: 'london'
}]

function b(idtosearch) {
  return a.filter(item => {
    return item.id === idtosearch
  })
};

console.log(b(1))

score:4

try this

  const type = array.isarray(this.props.cities) && this.props.cities.find(el => el.id ==this.props.enteredevent.cityid);
  this.setstate({ showinoption: type ? type.name : null });

make sure the name you enter matches with any one of the object in array


Related Query

More Query from same tag