I have found this previous answer that semi-answers my question but I want to return an array of the indexes in which they appear – in this case ** 18A38** would return the location [1,3].
Entries are only an example – the final version would have potentially hundreds of entries.
const checkArray = ['18A38']
const dataOject =
[ { id:'853K83', isGo:false }
, { id:'18A38', isGo:true }
, { id:'97T223', isGo:true }
, { id:'18A38', isGo:false }
, { id:'182B92', isGo:true }
];
const result = checkArray.map(val=>dataOject.findIndex(el=>el.id===val) )
console.log( JSON.stringify(result))
3
Answers
Just loop through and push the indices you need onto an array
checkArray
array is of length 1. Of course after usingmap
you’d get only one value back.I’d do it that way:
If potentially
checkArray
is of more values, you also could do:You can use Array.reduce() to do this