How to get the element second index in an array in javascript -
i have array follows
var arr = [10,12,34,23,12,89,34,12];
in have 12
3 times .i want find second index of 12 in javascript.is possible find.i tried lastindexof()
.but did not me.is there way find this.
thanks in advance...
one more possible solution:
array.prototype.nthindexof = function(e, n) { var index = -1; (var = 0, len = this.length; < len; i++) { if (i in && e === this[i] && !--n) { index = i; break; } } return index; }; [10, 12, 34, 23, 12, 89, 34, 12].nthindexof(12, 2); // >> 4
Comments
Post a Comment