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

Coding for Kids

What is coding? In coding we build a program to do a specific task for us. Code: A code is a set of computer instructions and when you will ...