ARTICLE AD BOX
Yes — you can do this without switching to a for loop.
Array.prototype.filter() provides the index as the second argument to the callback. You just need to include it in the returned result.
function findObjectsByProperty(array, property, value) { return array .map((obj, index) => ({ obj, index })) .filter(item => item.obj[property] === value); } [ { obj: { id: 1, title: 'Book A', genre: 'Fiction' }, index: 0 }, { obj: { id: 3, title: 'Book C', genre: 'Fiction' }, index: 2 } ] const fictionBooks = books .map((book, index) => ({ ...book, index })) .filter(book => book.genre === 'Fiction');

