0

How can I return object value based on array value in JavaScript.

Array Object:

const options = [
  { value: 'a', label: 'Apple' },
  { value: 'b', label: 'Boy' },
  { value: 'd', label: 'Boy' },
];

Array:

const status = ['a', 'b', 'c'];

Output expectation:

result = ['Apple', 'Boy']

I tried as below but it gives me a whole object in return

options.filter(option => status.includes(option.value))
  • 1
    Yes. you almost finish it. you only need to add ```.map(el=>el.label)``` after ```filter()``` to return the result. – ikhvjs Jun 29 '21 at 14:10
  • 2
    `options.filter(option => status.includes(option.value)).map(item => (item.label))` – Irfan wani Jun 29 '21 at 14:16

0 Answers0