Arrays VII
1.
What is the result of `[1, 2, 3].every(x => x > 0)`?
undefined
FALSE
null
TRUE
2.
Given the array `var nums = [1, 2, 3];`, what is the result of `nums.pop()`?
null
2
1
3
3.
Given the array `var fruits = ['apple', 'banana', 'orange'];`, what is the result of `fruits.slice(0, 2)`?
['apple', 'banana', 'orange']
['apple', 'banana']
['banana', 'orange']
['orange', 'banana', 'apple']
4.
How do you check if an array is equal to another array in JavaScript?
array1.isEqual(array2)
array1.equals(array2)
arraysEqual(array1, array2)
JSON.stringify(array1) === JSON.stringify(array2)
5.
What will the following code output: `[1, 2, 3].join(' - ')`?
'1 - 2 - 3'
'1,2,3'
'123'
[1, 2, 3]
6.
How can you check if an element exists at a specific index in an array?
array.elementExist(index)
array.includes(index)
index in array
typeof array[index] !== 'undefined'
7.
How do you remove the first element from an array in JavaScript?
array.slice(1)
array.splice(0, 1)
array.remove(0)
array.shift()
8.
What does the `Array.from()` method do when applied to an array?
Creates a shallow copy of the array
Converts the array to a string
Adds new elements to the array
Sorts the elements of the array
9.
How do you convert an array-like object to an array in JavaScript?
object.toArray()
Array.from(object)
Array.of(object)
Array.makeArray(object)
10.
How can you find the unique values in an array in JavaScript?
array.unique()
Array.from(new Set(array))
array.getUnique()
array.removeDuplicates()
11.
What is the purpose of the `Array.prototype.fill()` method?
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
12.
How do you concatenate two arrays in JavaScript without modifying the original arrays?
array1.concat(array2)
[...array1, ...array2]
array1.append(array2)
array1.join(array2)
13.
What does the `Array.prototype.lastIndexOf()` method return if the element is not found?
undefined
null
-1
0
14.
How can you remove the first occurrence of a specific element from an array?
array.removeFirst(element)
array.splice(array.indexOf(element), 1)
array.delete(element)
array.exclude(element)
15.
What is the result of `[1, 2, 3].findIndex(x => x > 2)`?
2
1
0
null
16.
How can you shuffle the elements of an array randomly?
array.randomize()
array.sort(() => Math.random() - 0.5)
array.shuffle()
array.mix()
17.
What will the following code output: `[1, 2, 3].filter(x => x > 1)`?
[3]
[1]
[1, 2]
[2, 3]
18.
What is the purpose of the `Array.prototype.reduceRight()` method?
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
19.
Given the array `var numbers = [2, 4, 6, 8, 10];`, what is the result of `numbers.slice(1, 3)`?
[6, 8]
[2, 4]
[4, 6]
[4, 6, 8]
20.
What is the purpose of the `some()` method in JavaScript arrays?
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