Worksheetsfind element in the list
Total questions: 10
Worksheet time: 5mins
What does the indexOf method do in JavaScript?
Adds an element to the end of an array
Removes the first element from an array
Finds the index of a specified element in an array
Sorts the elements of an array
What will fruits.indexOf("banana") return if fruits = ["apple", "banana", "cherry"]?
0
1
2
-1
If an element is not found in the array, what does indexOf return?
0
-1
null
undefined
Which of the following is the correct syntax for using indexOf?
array.indexOf(element)
indexOf(array, element)
array.index(element)
array.findIndex(element)
What will numbers.indexOf(5) return if numbers = [1, 2, 3, 4, 5, 6]?
4
5
6
-1
Which method can be used to find the index of the first occurrence of an element in an array?
find()
indexOf()
includes()
filter()
What will colors.indexOf("blue") return if colors = ["red", "green", "blue", "yellow"]?
1
2
3
4
If indexOf is used on an array with duplicate elements, what will it return?
The index of the first occurrence of the element
The index of the last occurrence of the element
The total number of occurrences of the element
An array of all indices where the element occurs
What will animals.indexOf("cat") return if animals = ["dog", "cat", "bird", "fish"]?
0
1
2
3
Which of the following statements is true about the indexOf method?
It modifies the original array
It returns the index of the element if found, otherwise -1
It can only be used on arrays of numbers
It always returns the last index of the element
