Skip to content
QuiznExam

JavaScript Arrays & Array Methods Quiz – 20 Questions with Answers

Test your JavaScript knowledge with 20 questions covering arrays, array creation, indexing, adding and removing elements, and commonly used array methods such as map(), filter(), reduce(), find(), some(), every(), and sort().

20
Questions
15 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. Which syntax correctly creates an array containing the values 10, 20, and 30 in JavaScript?

    • A. let numbers = [10, 20, 30];
    • B. let numbers = (10, 20, 30);
    • C. let numbers = {10, 20, 30};
    • D. let numbers = <10, 20, 30>;
    Show answer

    A. let numbers = [10, 20, 30];

    JavaScript arrays can be created using square brackets with comma-separated elements.

  2. 2. What is the index of the first element in a JavaScript array?

    • A. 0
    • B. 1
    • C. -1
    • D. Depends on the array
    Show answer

    A. 0

    JavaScript arrays use zero-based indexing, so the first element has index 0.

  3. 3. What is the value of numbers[2] in the following code? let numbers = [10, 20, 30, 40];

    • A. 10
    • B. 20
    • C. 30
    • D. 40
    Show answer

    C. 30

    The third element is stored at index 2 because JavaScript arrays start indexing from 0.

  4. 4. Which property returns the number of elements in a JavaScript array?

    • A. size
    • B. count
    • C. length
    • D. items
    Show answer

    C. length

    The length property returns the number of elements in an array.

  5. 5. Which array method adds one or more elements to the end of an array?

    • A. push()
    • B. pop()
    • C. shift()
    • D. unshift()
    Show answer

    A. push()

    The push() method adds one or more elements to the end of an array and returns the new array length.

  6. 6. Which array method removes the last element from an array?

    • A. shift()
    • B. pop()
    • C. remove()
    • D. delete()
    Show answer

    B. pop()

    The pop() method removes and returns the last element of an array.

  7. 7. Which method adds one or more elements to the beginning of an array?

    • A. push()
    • B. append()
    • C. unshift()
    • D. prepend()
    Show answer

    C. unshift()

    The unshift() method adds one or more elements to the beginning of an array and returns the new array length.

  8. 8. Which method removes the first element from an array?

    • A. shift()
    • B. pop()
    • C. removeFirst()
    • D. deleteFirst()
    Show answer

    A. shift()

    The shift() method removes and returns the first element of an array.

  9. 9. What does the map() method primarily do?

    • A. Sorts an array in place
    • B. Creates a new array by transforming each element
    • C. Removes the first element
    • D. Checks whether an array is empty
    Show answer

    B. Creates a new array by transforming each element

    The map() method calls a callback for each array element and returns a new array containing the callback results.

  10. 10. What is the result of this code? let numbers = [1, 2, 3]; let result = numbers.map(n => n * 2);

    • A. [1, 2, 3]
    • B. [2, 3, 4]
    • C. [2, 4, 6]
    • D. [1, 4, 9]
    Show answer

    C. [2, 4, 6]

    map() multiplies each element by 2 and returns the new array [2, 4, 6].

  11. 11. What does the filter() method return?

    • A. A single matching element
    • B. A new array containing elements that pass the test
    • C. The original array length
    • D. A Boolean value only
    Show answer

    B. A new array containing elements that pass the test

    filter() creates a new array containing the elements for which the callback returns a truthy value.

  12. 12. What is the result of this code? let numbers = [1, 2, 3, 4, 5]; let result = numbers.filter(n => n % 2 === 0);

    • A. [1, 3, 5]
    • B. [2, 4]
    • C. [1, 2, 3, 4, 5]
    • D. [0, 2, 4]
    Show answer

    B. [2, 4]

    The filter condition keeps numbers whose remainder when divided by 2 is zero, producing [2, 4].

  13. 13. What does the reduce() method commonly do?

    • A. Reduces an array to a single accumulated value
    • B. Always removes the last element
    • C. Sorts an array alphabetically
    • D. Creates a copy without changing values
    Show answer

    A. Reduces an array to a single accumulated value

    reduce() processes array elements using an accumulator and can produce a single final value such as a sum or object.

  14. 14. What is the result of this code? let numbers = [1, 2, 3, 4]; let total = numbers.reduce((sum, n) => sum + n, 0);

    • A. 4
    • B. 6
    • C. 10
    • D. 24
    Show answer

    C. 10

    The reduce() operation starts with 0 and adds 1, 2, 3, and 4, producing a total of 10.

  15. 15. Which method returns the first array element that satisfies a given condition?

    • A. filter()
    • B. find()
    • C. search()
    • D. first()
    Show answer

    B. find()

    The find() method returns the first element for which the callback returns a truthy value, or undefined if no element matches.

  16. 16. Which method checks whether at least one array element satisfies a condition?

    • A. every()
    • B. some()
    • C. anyMatch()
    • D. exists()
    Show answer

    B. some()

    The some() method returns true when at least one element passes the provided test.

  17. 17. Which method checks whether all array elements satisfy a condition?

    • A. all()
    • B. every()
    • C. each()
    • D. allMatch()
    Show answer

    B. every()

    The every() method returns true only when all elements pass the provided test.

  18. 18. What does the includes() method do when used on an array?

    • A. Checks whether the array contains a specified value
    • B. Adds a specified value
    • C. Removes a specified value
    • D. Converts the array into a string
    Show answer

    A. Checks whether the array contains a specified value

    The includes() method returns true if the array contains the specified value and false otherwise.

  19. 19. What is the result of this code? let numbers = [3, 1, 2]; numbers.sort();

    • A. [3, 2, 1]
    • B. [1, 2, 3]
    • C. [2, 3, 1]
    • D. [3, 1, 2]
    Show answer

    B. [1, 2, 3]

    For an array of these numeric values, the default sort order produces [1, 2, 3]. The default comparison is lexicographic, so a numeric comparator is needed for general numeric sorting.

  20. 20. Which method can be used to combine all elements of an array into a string using a specified separator?

    • A. join()
    • B. combine()
    • C. merge()
    • D. concatString()
    Show answer

    A. join()

    The join() method creates a string by concatenating array elements with a specified separator.