Say we have this array:
arr = [[3, 3], [3, 4], [3, 5], [3, 6]]
And we have this conditional:
arr = [[3, 3], [3, 4], [3, 5], [3, 6]]
for(let i = 0; i < arr.length; i++){
if (arr[i][0] === 3 && arr[i][1] === 4 || arr[i][0] === 3 && arr[i][1] === 5){
console.log(i)
}
}
There respective indexes would be 1 and 2, which would display in the console.log() in sequential order.
How would I grab the minimum index (1 in this case), specifically, from that? I cannot store the numbers in an array due to my use case, so I need to establish the minimum within the loop. And you can't really set a min number because you won't know which element index will be the smallest beforehand.
Is this possible or am I overthinking it hard?
findIndex. It returns the index once the first result is found.i = arr.findIndex(a => a[0] === 3 && a[1] === 4 || a[0] === 3 && a[1] === 5)