javascript indexof array – JavaScript Array indexOf() 5+ Examples

javascript indexof array : The JavaScript array indexOf() method is used to search the position of a particular element in a given array. let’s start Introduction to the JavaScript array indexOf() method.

JavaScript Array indexOf() Syntax is :


javascript indexof array Examples

Example 1


Example 2


Example 3


JavaScript Array indexOf and lastIndexOf: Locating an Element in an Array

var playerids = [10, 20, 30, 10, 40, 20];

console.log(playerids.indexOf(10)); // 0
console.log(playerids.indexOf(30)); // 2
console.log(playerids.indexOf(50)); // -1
console.log(playerids.indexOf(20)); // 1
const websites = ["gpseoagency", "itsolutionstuck", "Pakainfo", "infinityknow"];
let index = websites.indexOf("Pakainfo");
const websites = ["gpseoagency", "itsolutionstuck", "Pakainfo", "infinityknow", "Pakainfo"];
let index = websites.indexOf("Pakainfo", 3);

JavaScript array lastIndexOf() method

console.log(playerids.lastIndexOf(10));// 3
console.log(playerids.lastIndexOf(20));// 5
console.log(playerids.lastIndexOf(50));// -1

I hope you get an idea about javascript indexof array.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment