Tuesday, June 12, 2018

JavaScript - Array Methods - indexOf

Below code demonstrates the usage of indexOf method:

var Arr1 = [1,2,3,4,5,6];

Arr1.unshift("newElem");
Arr1[Arr1.indexOf("newElem")] = "oldElem";

console.log(Arr1);

Refer:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf

Practice at:
http://jsbin.com

No comments:

Post a Comment