Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Can anyone tell me what’s the difference between indexof and findindex function in JavaScript?

1 Answer

0 votes
by (19.7k points)

indexOf() - it returns the first occurrence of an element which can be found in the array. It returns -1, if the element is not present. 

Below is the example for indexOf():

Const list_of_fruits = ['orange', 'apple', 'mango', 'strawberry', 'kiwi', ‘orange’];

console.log(list_of_fruits.indexOf('orange'));

// output: 0

// starts from index 1

console.log(lists_of_fruits.indexOf('orange', 1));

// output: 5

console.log(list_of_fruits.indexOf('banana'));

// -1

If you want to learn more about Javathen go through this Java tutorial by Intellipaat for more insights.

Related questions

0 votes
1 answer
asked Feb 12, 2021 in Java by sheela_singh (9.5k points)
+11 votes
2 answers
asked May 23, 2019 in Java by prachi95 (1.1k points)
0 votes
1 answer
asked Apr 4, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 13, 2019 in SQL by Tech4ever (20.3k points)

Browse Categories

...