Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

find element in the list

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What does the indexOf method do in JavaScript?

a)

Adds an element to the end of an array

b)

Removes the first element from an array

c)

Finds the index of a specified element in an array

d)

Sorts the elements of an array

2.

What will fruits.indexOf("banana") return if fruits = ["apple", "banana", "cherry"]?

a)

0

b)

1

c)

2

d)

-1

3.

If an element is not found in the array, what does indexOf return?

a)

0

b)

-1

c)

null

d)

undefined

4.

Which of the following is the correct syntax for using indexOf?

a)

array.indexOf(element)

b)

indexOf(array, element)

c)

array.index(element)

d)

array.findIndex(element)

5.

What will numbers.indexOf(5) return if numbers = [1, 2, 3, 4, 5, 6]?

a)

4

b)

5

c)

6

d)

-1

6.

Which method can be used to find the index of the first occurrence of an element in an array?

a)

find()

b)

indexOf()

c)

includes()

d)

filter()

7.

What will colors.indexOf("blue") return if colors = ["red", "green", "blue", "yellow"]?

a)

1

b)

2

c)

3

d)

4

8.

If indexOf is used on an array with duplicate elements, what will it return?

a)

The index of the first occurrence of the element

b)

The index of the last occurrence of the element

c)

The total number of occurrences of the element

d)

An array of all indices where the element occurs

9.

What will animals.indexOf("cat") return if animals = ["dog", "cat", "bird", "fish"]?

a)

0

b)

1

c)

2

d)

3

10.

Which of the following statements is true about the indexOf method?

a)

It modifies the original array

b)

It returns the index of the element if found, otherwise -1

c)

It can only be used on arrays of numbers

d)

It always returns the last index of the element