Practice question from Prerequisites & Fundamentals

What is the output of this code? A. 0 B. 1 C. 2 D. 3 E. undefined

const items = [10, 20, 30];
const result = items.filter(x => x > 15);
console.log(result.length);

Answer

C

Explanation

The filter() method keeps only elements greater than 15, which are 20 and 30. The resulting array has a length of 2.

More questions from React