Arrays X
1.
What is the result of `Array.from('Hello', x => x.charCodeAt(0))`?
[Hello]
[72, 101, 108, 108, 111]
[0, 1, 2, 3, 4]
[undefined, undefined, undefined, undefined, undefined]
2.
How can you find the index of the maximum value in an array?
array.indexOf(Math.max(...array))
array.maxIndex()
maxIndex(array)
array.indexOfMax()
3.
How can you find the intersection of two arrays in JavaScript?
All of the above
array1.intersect(array2)
array1.common(array2)
array1.filter(item => array2.includes(item))
4.
How do you check if an array contains only unique elements in JavaScript?
array.length === new Set(array).size
array.unique()
array.isUnique()
array.allUnique()
5.
What is the purpose of the `Array.prototype.flat()` method in JavaScript?
Removes elements from the array
Sorts the elements of an array
Adds new elements to the array
Flattens a nested array
6.
How can you remove the last two elements from an array in JavaScript?
array.splice(-2)
array.removeLast(2)
array.slice(0, -2)
array.pop(2)
7.
What is the purpose of the `Array.prototype.keys()` method in JavaScript?
Returns an iterator of key/value pairs
Returns an iterator of array values
Returns an iterator of array indices
Returns an iterator of array elements
8.
Given the array `var nums = [1, 2, 3, 4, 5];`, what is the result of `nums.map((num, index) => num + index)`?
[0, 1, 2, 3, 4]
[2, 4, 6, 8, 10]
[1, 2, 3, 4, 5]
[1, 3, 5, 7, 9]
9.
What does the `Array.prototype.unshift()` method do in JavaScript?
Adds one or more elements to the beginning of an array
Adds one or more elements to the end of an array
Removes the first element from an array
Sorts the elements of an array
10.
How can you find the difference between two arrays in JavaScript?
array1.difference(array2)
array1.filter(item => !array2.includes(item))
array1.subtract(array2)
All of the above
11.
What is the result of `Array(3).fill(0)`?
[0, 0, 0]
[3, 3, 3]
[undefined, undefined, undefined]
[0]
12.
What is the purpose of the `Array.prototype.unshift()` method in JavaScript?
Sorts the elements of an array
Adds one or more elements to the end of an array
Removes the first element from an array
Adds one or more elements to the beginning of an array
13.
Given the array `var nums = [1, 2, 3, 4, 5];`, what is the result of `nums.reduce((acc, num) => acc + num, 10)`?
[11, 12, 13, 14, 15]
15
10
25
14.
What is the purpose of the `Array.prototype.fill()` method in JavaScript?
Removes elements from the array
Adds new elements to the array
Fills all elements of an array with a static value
Sorts the elements of an array
15.
How can you find the union of two arrays in JavaScript?
Array.from(new Set([...array1, ...array2]))
array1.union(array2)
array1.combine(array2)
All of the above
16.
What will the following code output: `[1, 2, 3].reverse()`?
[2, 1]
[1, 2, 3]
[3]
[3, 2, 1]
17.
What is the result of `Array.from({ length: 3 }, (_, index) => index)`?
[undefined, undefined, undefined]
[0, 1, 2]
[3, 2, 1]
[1, 2, 3]
18.
How can you find the index of the minimum value in an array?
array.indexOfMin()
array.minIndex()
minIndex(array)
array.indexOf(Math.min(...array))
19.
How can you check if an array contains only falsy values in JavaScript?
array.every(element => !element)
array.isFalsy()
array.allFalsy()
array.checkFalsy()
20.
How do you check if an array contains only truthy values in JavaScript?
array.checkTruthy()
array.isTruthy()
array.allTruthy()
array.every(Boolean)