wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Moringa JavaScript Arrays

Total questions: 10

Worksheet time: 7mins

Name
Class
Date
1.

Which of the following is not false?

a)

JavaScript arrays are resizable and can contain a mix of different data types.

b)

JavaScript arrays are not associative arrays and are zero-indexed.

c)

Methods used to create copies i.e spread-syntax, slice(), concat(), and Array.from() methods create shallow copies of the array.

d)

JavaScript arrays are not objects but their own primitive types.

2.

How do you create an array in JavaScript?

a)

const fruits = ['Apple', 'Banana'];

b)

const fruits = new Array('Apple', 'Banana');

c)

const fruits = 'Apple, Banana'.split(', ');

d)

const fruits = [];

fruits[0]= 'Apple';

fruits[1] = 'Banana';

3.

The (a)   Array object property gives us the count of items in an Array.

4.

Which of the following code will return `undefined` using the following array?

const fruits = ['Apple', 'Banana'];

a)

fruits[-1];

b)

fruits[fruits.length - 1];

c)

fruits[1];

d)

fruits[0];

5.

The (a)   method is used to find the position (index) of the string "Banana" in the array;

const fruits = ['Apple', 'Banana'];

6.

The following lines of code are used to check if an item exists. What is the result of the expression?

const fruits = ['Apple', 'Banana'];

fruits.includes('Banana') === fruits.indexOf('Banana') !== -1;

a)

true

b)

false

7.

Which of the following correctly loops through the Array?

const fruits = ['Apple', 'Mango', 'Cherry'];

a)

for (const fruit in fruits) {

console.log(fruit);

}

b)

fruits.forEach(function(fruit, index, array) {

console.log(fruit);

});

8.

Which of the following is false about iterating through arrays?

a)

The Array find() method returns the index of the 1st element that satisfies the provided testing function. If no values satisfy the testing function, -1 is returned.

b)

The Array filter() method creates a new array with all elements that pass the test implemented by the provided function.

c)

The Array reduce() method executes a callback function on each element. The final result of running the reducer across all array elements is a single value.

d)

The Array map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

9.

The Array. (a)   () method determines whether the passed value is actually an array

10.

What is the output of the following code?

const letters = ['A', 'B', 'A', 'C', 'B'];

console.log([...new Set(letters)]);

a)

['A', 'B', 'C']

b)

[['A', 'A'], ['B', 'B'], ['C']]

c)

[['A', 'A'], ['B', 'B'], 'C']