Skip to content

Instantly share code, notes, and snippets.

@rodrwan
Last active May 22, 2017 00:02
Show Gist options
  • Save rodrwan/26af9f4b7d525ee7637915b88eeabf43 to your computer and use it in GitHub Desktop.
Save rodrwan/26af9f4b7d525ee7637915b88eeabf43 to your computer and use it in GitHub Desktop.
const arr = [3,2,5,6,23,86,34,45];
const toFind = 23;
function indexOf (arr, num) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === toFind) {
return i;
}
}
return -1;
}
console.log(indexOf(arr, toFind));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment