Arrays III
1.
How do you check if an array is empty in JavaScript?
array.empty()
isEmpty(array)
array.isEmpty()
array.length === 0
2.
What is the result of `Array(3).fill(0)` in JavaScript?
[0]
[3, 3, 3]
[0, 0, 0]
[undefined, undefined, undefined]
3.
How can you shuffle the elements of an array randomly?
randomize(array)
shuffleArray(array)
array.sort(() => Math.random() - 0.5)
array.shuffle()
4.
How do you concatenate two arrays in JavaScript?
array.join(anotherArray)
array + anotherArray
array.concat(anotherArray)
concatenateArrays(array, anotherArray)
5.
What is the purpose of the `Array.prototype.find()` method?
Adds a new element to the array
Returns the first element that passes a test
Removes elements from the array
Sorts the elements of an array
6.
What is the result of `[1, 2, 3].reverse().join('-')`?
'1-2-3'
'3-2-1'
[3, 2, 1]
'123'
7.
What will the following code output: `['apple', 'banana'].indexOf('orange')`?
-1
0
1
FALSE
8.
How can you find the index of the maximum value in an array?
array.maxIndex()
array.indexOf(Math.max(...array))
array.findIndex(max(array))
array.indexOfMax()
9.
Given the array `var nums = [1, 2, 3];`, what is the result of `nums.includes(4)`?
null
TRUE
FALSE
undefined
10.
What does the `Array.from()` method do in JavaScript?
Sorts the elements of an array
Converts an array to a string
Creates a new array from an iterable object
Adds new elements to the array
11.
How do you remove duplicate elements from an array?
Array.from(new Set(array))
array.unique()
removeDuplicates(array)
array.removeDuplicates()
12.
What does the `Array.isArray()` method return if the argument is not an array?
TypeError
null
undefined
FALSE
13.
Given the array `var fruits = ['apple', 'banana', 'orange'];`, what is the result of `fruits.slice(1)`?
['apple']
['apple', 'banana']
['banana', 'orange']
['orange']
14.
What will the following code output: `[1, 2, 3].filter(x => x > 1)`?
[1]
[2, 3]
[1, 2]
[3]
15.
What is the purpose of the `Array.prototype.some()` method?
Sorts the elements of an array
Adds a new element to the array
Removes elements from the array
Checks if at least one element passes a test
16.
What does the `Array.prototype.every()` method do in JavaScript?
Removes elements from the array
Adds a new element to the array
Checks if all elements pass a test
Sorts the elements of an array
17.
Given the array `var numbers = [2, 4, 6, 8, 10];`, what is the result of `numbers.map(x => x / 2)`?
[1, 2, 3, 4, 5]
[2, 4, 6, 8, 10]
[1, 4, 9, 16, 25]
[1, 2, 3, 4, 5, 2, 4, 6, 8, 10]
18.
How can you flatten a nested array in JavaScript?
array.flat()
flattenArray(array)
array.flatten()
flatArray(array)
19.
What does the `Array.prototype.reduceRight()` method do?
Removes elements from the array
Reduces the array to a single value
Adds new elements to the array
Applies a function against an accumulator and each element in reverse order
20.
How do you check if two arrays are equal in JavaScript?
array1.isEqual(array2)
JSON.stringify(array1) === JSON.stringify(array2)
arraysEqual(array1, array2)
array1.equals(array2)