Implementation of JavaScript indexOf() method


Took 3 minutes 37 seconds to code JavaScript indexOf() method. Here is the code snippet.

Code:
arr = ['1', '2', '3'];
function indexOf(arr, element) {
for (var i = 0; i < arr.length; i++) {
if (element === arr[i]) {
return i;
}
}
return -1;
}

document.write(indexOf(arr, '3'));

Result:
2

1 comment:

  1. The King Casino Resort - Hertzaman
    Find the ventureberg.com/ perfect place to herzamanindir.com/ stay, 토토사이트 play, apr casino and unwind at Harrah's jancasino.com Resort Southern California. Get your points now!

    ReplyDelete

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...