Arrays VI
1.
What is the result of `[1, 2, 3].findIndex(x => x > 2)`?
null
1
0
2
2.
What is the result of `[1, 2, 3].every(x => x > 0)`?
undefined
FALSE
null
TRUE
3.
Given the array `var nums = [1, 2, 3];`, what is the result of `nums.pop()`?
1
2
3
null
4.
What will the following code output: `[1, 2, 3].join(' - ')`?
'1 - 2 - 3'
'1,2,3'
'123'
[1, 2, 3]
5.
What does the `Array.prototype.lastIndexOf()` method return if the element is not found?
undefined
null
-1
0
6.
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]
7.
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)
8.
What is the purpose of the `Array.prototype.reduceRight()` method?
Adds new elements to the array
Reduces the array to a single value
Applies a function against an accumulator and each element in reverse order
Removes elements from the array
9.
How do you find the index of the last occurrence of a specific element in an array?
lastIndex()
findLastIndex()
indexOfLast()
lastIndexOf()
10.
1. How can you check if an array is sparse in JavaScript?
array.includes(undefined)
array.length === array.filter(Boolean).length
Object.keys(array).length === array.length
array.some(item => typeof item === 'undefined')
11.
How do you remove the first element from an array in JavaScript?
array.shift()
array.splice(0, 1)
array.remove(0)
array.slice(1)
12.
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
13.
How do you convert an array-like object to an array in JavaScript?
Array.makeArray(object)
object.toArray()
Array.of(object)
Array.from(object)
14.
How can you find the unique values in an array in JavaScript?
Array.from(new Set(array))
array.unique()
array.getUnique()
array.removeDuplicates()
15.
What is the purpose of the `Array.prototype.fill()` method?
Adds new elements to the array
Fills all elements of an array with a static value
Removes elements from the array
Sorts the elements of an array
16.
10. How do you concatenate two arrays in JavaScript without modifying the original arrays?
array1.concat(array2)
[...array1, ...array2]
array1.append(array2)
array1.join(array2)
17.
Given the array `var fruits = ['apple', 'banana', 'orange'];`, what is the result of `fruits.slice(0, 2)`?
['apple', 'banana']
['apple', 'banana', 'orange']
['banana', 'orange']
['orange', 'banana', 'apple']
18.
How can you remove the first occurrence of a specific element from an array?
array.delete(element)
array.removeFirst(element)
array.splice(array.indexOf(element), 1)
array.exclude(element)
19.
How can you shuffle the elements of an array randomly?
array.shuffle()
array.randomize()
array.sort(() => Math.random() - 0.5)
array.mix()
20.
What will the following code output: `[1, 2, 3].filter(x => x > 1)`?
[3]
[1]
[1, 2]
[2, 3]