get index in for loop node js code example Example: javascript for loop return index const targetindex = myarray.findIndex(item => item.name === 'xyz');