I have searched but I am not able to find an alternative to something like this in JS:
let i; for (i = 0; i < object.length && object[i] === 2; i++) {