Which of the following methods is used to find the index of an element in an array in JavaScript?

Which of the following methods is used to find the index of an element in an array in JavaScript?

a) indexOf()
b) findIndex()
c) find()
d) search()

Answer:

a) indexOf()

Explanation:

The indexOf() method returns the first index at which a given element can be found in an array, or -1 if the element is not present. It is useful for locating elements in arrays.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top