Daily JavaScript Quiz - 2024-04-24

  • Home /
  • Daily JavaScript Quiz - 2024-04-24

Daily Quiz - 2024-04-24

console.log([10, 20, 30].indexOf(20));

1

2

-1

20

The answer is Option 1

The indexOf() method in JavaScript returns the first index at which a given element can be found in the array, or -1 if it is not present.

In this case, you’re calling indexOf(20) on the array [10, 20, 30].

  • The element 20 is present in the array.

  • Its index is 1 (remember, array indices start from 0).

  • So, console.log([10, 20, 30].indexOf(20)); will output 1.

Javascript Quizzes