Arrays V
1.
What is the result of `[1, 2, 3].map(String)`?
[1, 2, 3]
['1', '2', '3']
123'
[1, '2', '3']
2.
What is the purpose of the `Array.prototype.copyWithin()` method?
Removes elements from the array
Duplicates the entire array
Adds new elements to the array
Copies a sequence of elements to a specified destination index
3.
How can you get the last element of an array in JavaScript?
array[-1]
array.last()
array.end()
array[array.length - 1]
4.
Given the array `var nums = [1, 2, 3];`, what is the result of `nums.reduceRight((acc, val) => acc + val)`?
6
1
5
0
5.
Given the array `var numbers = [1, 2, 3, 4, 5];`, what is the result of `numbers.slice(-2)`?
[1, 2, 3]
[4, 5]
[3, 4, 5]
[2, 3, 4, 5]
6.
How can you check if two arrays are deeply equal in JavaScript?
deepEqual(array1, array2)
array1.equals(array2)
arraysEqual(array1, array2)
JSON.stringify(array1) === JSON.stringify(array2)
7.
How do you check if an element exists at a specific index in an array?
array.has(index)
typeof array[index] !== 'undefined'
index in array
array.elementExist(index)
8.
How can you convert a string to an array of characters in JavaScript?
split(str)
str.toArray()
Array.from(str)
Array.of(str)
9.
What does the `Array.prototype.unshift()` method do in JavaScript?
Removes the last element from an array
Adds one or more elements to the beginning of an array
Sorts the elements of an array
Reverses the elements of an array
10.
How can you check if an array contains only unique elements?
array.isUnique()
array.unique()
new Set(array).size === array.length
array.onlyUnique()
11.
What does the `Array.prototype.splice()` method return?
A new array with removed elements
The modified original array
An array of removed elements
An empty array
12.
What is the purpose of the `Array.prototype.map()` method in JavaScript?
Adds a new element to the array
Creates a new array with the results of calling a provided function on every element
Removes elements from the array
Sorts the elements of an array
13.
What is the result of `[1, 2, 3].indexOf(2)`?
0
2
3
1
14.
How can you remove falsy values from an array in JavaScript?
array.excludeFalsy()
array.removeFalsy()
array.removeAllFalsy()
array.filter(Boolean)
15.
What does the `Array.prototype.join()` method do in JavaScript?
Sorts the elements of an array
Joins all elements of an array into a string using a specified separator
Adds a new element to the array
Removes elements from the array
16.
What does the `Array.prototype.forEach()` method do in JavaScript?
Sorts the elements of an array
Adds a new element to the array
Removes elements from the array
Executes a provided function once for each array element
17.
What is the result of `[1, 2, 3].find(x => x > 2)`?
1
3
2
null
18.
How can you add elements to the middle of an array in JavaScript?
array.splice(startIndex, 0, ...newElements)
array.insertMiddle(newElements)
array.addMiddle(newElements)
array.midInsert(startIndex, newElements)
19.
What will the following code output: `Array.from({ length: 3 }, (_, index) => index)`?
[0, 0, 0]
[1, 2, 3]
[0, 1, 2]
[undefined, undefined, undefined]
20.
Given the array `var fruits = ['apple', 'banana', 'orange'];`, what is the result of `fruits.filter(fruit => fruit.includes('a'))`?
['apple', 'banana']
['apple']
['banana', 'orange']
['orange']