javascript for loop return index

JavaScript
const targetindex = myarray.findIndex(item => item.name === 'xyz');

Source

Also in JavaScript: