Arrays IV
1.
How do you insert an element at a specific index in an array?
array.add(index, element)
array.insert(index, element)
array.splice(index, 0, element)
array.at(index, element)
2.
How can you find the minimum value in an array in JavaScript?
array.min()
Math.min(...array)
min(array)
array.minimum()
3.
What does the `Array.prototype.includes()` method return for non-primitive elements?
null
FALSE
TRUE
undefined
4.
What will the following code output: `[1, 2, 3].concat(4, [5, 6])`?
[1, 2, 3, 4, [5, 6]]
[1, 2, 3, [4, 5, 6]]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
5.
Given the array `var numbers = [1, 2, 3, 4, 5];`, what is the result of `numbers.filter(x => x % 2 !== 0)`?
[2, 4]
[1, 3, 5]
[1, 2]
[3, 5]
6.
What will the following code output: `[1, 2, 3].slice(1)`?
[1, 2]
[2, 3]
[3]
[1]
7.
What will the following code output: `[1, 2, 3].concat([4, 5, 6], [7, 8, 9])`?
[1, 2, 3, [4, 5], [6, 7, 8, 9]]
[1, 2, 3, [4, 5, 6], [7, 8, 9]]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
8.
What does the `Array.prototype.reverse()` method do in JavaScript?
Removes elements from the array
Sorts the elements of an array
Adds new elements to the array
Reverses the order of elements in the array
9.
Given the array `var fruits = ['apple', 'banana', 'orange'];`, what is the result of `fruits.map(fruit => fruit.length)`?
[5, 6, 6]
[5, 6]
[apple, banana, orange]
[1, 2, 2]
10.
What is the purpose of the `Array.prototype.flat()` method?
Removes elements from the array
Sorts the elements of an array
Adds new elements to the array
Flattens a nested array
11.
How can you find the sum of all elements in an array?
array.sum()
array.reduce((acc, val) => acc + val, 0)
array.total()
array.aggregate((acc, val) => acc + val)
12.
What will the following code output: `[1, 2, 3, 4].filter(x => x % 2 === 0)`?
[1, 2]
[1, 3]
[2, 4]
[4]
13.
How can you reverse the order of elements in an array without modifying the original array?
array.slice().reverse()
array.flip()
array.reverseCopy()
array.clone().reverse()
14.
How do you remove the first and last elements from an array?
array.slice(1, -1)
array.trim()
array.cut()
array.remove(0, array.length - 1)
15.
What will the following code output: `[1, 2, 3, 4].reduce((acc, val) => acc * val)`?
1
120
10
24
16.
What does the `Array.prototype.findIndex()` method return if the element is not found?
undefined
null
-1
0
17.
How do you remove the last three elements from an array?
array.removeLast(3)
array.splice(array.length - 3, 3)
array.cut(-3)
array.pop(3)
18.
What is the result of `Array.from({ length: 5 }, (_, index) => index * 2)`?
[0, 1, 2, 3, 4]
[2, 4, 6, 8, 10]
[0, 2, 4, 6, 8]
[undefined, undefined, undefined, undefined, undefined]
19.
How can you remove all occurrences of a specific element from an array?
array.remove(specificElement)
array.removeAll(specificElement)
array.filter(item => item !== specificElement)
array.exclude(specificElement)
20.
What is the result of `Array.from('hello')`?
['h', 'e', 'l', 'l', 'o']
['hello']
hello'
['h', 'e', 'l', 'l']