Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz - JavaScript Array Methods

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which array method removes the last element from an array in JavaScript?

a)

shift()

b)

pop()

c)

unshift()

d)

push()

2.

What does the `length` property of a JavaScript array return?

a)

The number of elements in the array

b)

The value of the last element

c)

The index of the first element

d)

The type of the array

3.

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

a)

push()

b)

pop()

c)

unshift()

d)

shift()

4.

How do you access the third element in an array called `colors`?

a)

colors[2]

b)

colors[3]

c)

colors(2)

d)

colors{2}

5.

Given the array `let numbers = [5, 2, 9, 1];`, what will `numbers.sort()` return?

a)

[5, 2, 9, 1]

b)

[1, 2, 5, 9]

c)

[9, 5, 2, 1]

d)

[2, 5, 9, 1]

6.

If you use `push("apple")` on the array `fruits = ["banana", "orange"]`, what will the new array be?

a)

["apple", "banana", "orange"]

b)

["banana", "orange", "apple"]

c)

["banana", "apple", "orange"]

d)

["orange", "banana", "apple"]

7.

What will be the result of the following code?
let arr = [10, 20, 30, 40];
arr.shift();

a)

[10, 20, 30, 40]

b)

[20, 30, 40]

c)

[10, 30, 40]

d)

[10, 20, 30]

8.

Given `let items = ["pen", "pencil", "eraser"];`, which statement will add "marker" to the start of the array?

a)

items.push("marker");

b)

items.unshift("marker");

c)

items.shift("marker");

d)

items.pop("marker");

9.

You have an array `let scores = [12, 8, 15, 7];`. Write a sequence of array method calls to remove the first and last elements, then add the number 20 to the end. What is the final array?

a)

[8, 15, 20]

b)

[12, 8, 15, 20]

c)

[8, 15, 7, 20]

d)

[15, 7, 20]

10.

Suppose you have `let arr = [3, 1, 4, 2];`. You want to sort the array in descending order and then remove the first element. What is the resulting array?

a)

[4, 3, 2]

b)

[3, 2, 1]

c)

[2, 1, 3]

d)

[1, 2, 3]