Arrays IX
1.
How can you check if an array is empty in JavaScript?
array.hasElements()
array.isEmpty()
array.length === 0
array.notEmpty()
2.
Given the array `var nums = [1, 2, 3, 4, 5];`, what is the result of `nums.slice(2, -1)`?
[3, 4]
[1, 2, 3]
[2, 3, 4]
[5]
3.
How can you check if an array contains a specific element in JavaScript?
array.contains(element)
array.has(element)
element in array
array.includes(element)
4.
What does the `Array.prototype.splice()` method do in JavaScript?
Sorts the elements of an array
Adds a new element to the array
Removes elements from the array
Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place
5.
What is the result of `[1, 2, 3].map(x => x * 2)`?
[1, 2, 3, 1, 2, 3]
[2, 4, 6]
[1, 2, 3, 2, 4, 6]
[2, 1, 3, 4, 6]
6.
What is the result of `Array.from('Hello')`?
['Hello']
['H', 'e', 'l', 'l', 'o']
['H', 'e', 'l', 'l']
['olleH']
7.
How can you remove a specific element from an array in JavaScript?
array.filter(item => item !== element)
array.remove(element)
array.exclude(element)
All of the above
8.
What is the result of `Array.of(1, 2, 3)`?
[1, 2, 3]
[1, [2, 3]]
[1, 1, 1]
[1, 2, 2, 3, 3]
9.
How do you add elements to the end of an array in JavaScript?
array.add(element)
array.push(element)
array.append(element)
array.insertEnd(element)
10.
What is the purpose of the `Array.prototype.filter()` method in JavaScript?
Adds a new element to the array
Creates a new array with elements that pass a test
Removes elements from the array
Sorts the elements of an array
11.
How can you iterate over the elements of an array in JavaScript?
array.forEach((element, index) => {...})
for (let i = 0; i < array.length; i++) {...}
for (const element of array) {...}
All of the above
12.
What is the purpose of the `Array.prototype.reduce()` method in JavaScript?
Sorts the elements of an array
Adds a new element to the array
Removes elements from the array
Reduces the array to a single value
13.
How do you find the minimum value in an array in JavaScript?
array.min()
Math.min(...array)
min(array)
array.minimum()
14.
What is the result of `[1, 2, 3].concat([4, 5])`?
[1, 2, 3, 5, 4]
[1, 2, 3, [4, 5]]
[1, [2, 3], 4, 5]
[1, 2, 3, 4, 5]
15.
What is the purpose of the `Array.prototype.slice()` method in JavaScript?
Removes elements from the array
Adds new elements to the array
Returns a shallow copy of a portion of an array into a new array
Sorts the elements of an array
16.
Given the array `var fruits = ['apple', 'banana', 'orange'];`, what is the result of `fruits.indexOf('banana')`?
-1
2
0
1
17.
How do you check if all elements in an array satisfy a condition in JavaScript?
All of the above
array.all((element) => condition)
array.check((element) => condition)
array.every((element) => condition)
18.
How can you find the index of the last occurrence of a specific element in an array?
array.findLastIndex(element)
array.lastIndex(element)
array.indexOfLast(element)
array.lastIndexOf(element)
19.
What is the purpose of the `Array.prototype.join()` method 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
20.
How do you flatten a nested array in JavaScript?
array.flat()
array.flatten()
array.reduce((acc, val) => acc.concat(val), [])
All of the above