Arrays II
1.
What is the purpose of the `concat` method in JavaScript arrays?
Splits an array into multiple arrays
Combines two or more arrays
Adds a new element to the array
Reverses the elements of an array
2.
What does the `fill()` method do in JavaScript arrays?
Fills all elements of an array with a static value
Adds new elements to the array
Removes elements from the array
Sorts the elements of an array
3.
What does the `join()` method do in JavaScript arrays?
Adds a new element to the array
Splits an array into multiple arrays
Joins all elements of an array into a string using a specified separator
Reverses the elements of an array
4.
What will the following code output: `[1, 2, 3].toString()`?
'1-2-3'
[1, 2, 3]
'123'
'1,2,3'
5.
What will the following code output: `[1, 2, 3].join('-')`?
1-2-3'
[1, 2, 3]
123'
1,2,3'
6.
How do you remove the last element from an array without modifying the original array?
splice()
pop()
slice()
filter()
7.
Given the array `var nums = [1, 2, 3];`, what is the result of `nums.concat([4, 5], [6, 7])`?
[1, 2, 3, 4, 5]
[1, 2, 3, [4, 5], [6, 7]]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, [4, 5, 6, 7]]
8.
What is the difference between `slice()` and `splice()` methods in JavaScript?
slice() extracts without modifying, splice() modifies the original array
slice() modifies the original array, splice() extracts without modifying
Both modify the original array
Both extract without modifying
9.
What does the `reduce()` method do in JavaScript arrays?
Reduces the array to a single value
Adds new elements to the array
Removes elements from the array
Sorts the elements of an array
10.
How do you find the index of the first occurrence of a specific element in an array?
findIndex()
searchIndex()
indexOf()
getPosition()
11.
If you have an array `var colors = ['red', 'green', 'blue'];`, how do you replace 'green' with 'yellow'?
colors.swap('green', 'yellow');
colors.replace('green', 'yellow');
colors[1] = 'yellow';
colors.splice(1, 1, 'yellow');
12.
What is the purpose of the `filter` method in JavaScript arrays?
Creates a new array with elements that pass a test
Removes elements from the array
Sorts the elements of an array
Adds new elements to the array
13.
How do you check if all elements in an array satisfy a condition?
check()
all()
each()
every()
14.
Given the array `var numbers = [1, 2, 3, 4, 5];`, what is the result of `numbers.map(x => x * 2)`?
[1, 4, 9, 16, 25]
[2, 4, 6, 8, 10]
[1, 2, 3, 4, 5, 2, 4, 6, 8, 10]
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
15.
How do you reverse the order of elements in an array without modifying the original array?
map().reverse()
reverse()
concat().reverse()
slice().reverse()
16.
Given the array `var fruits = ['apple', 'banana', 'orange'];`, what is the result of `fruits.includes('banana', 1)`?
TRUE
FALSE
null
undefined
17.
How do you remove elements with a specific value from an array in JavaScript?
exclude()
remove()
delete()
filter()
18.
What is the purpose of the `isArray` method in JavaScript?
Adds a new element to the array
Checks if a variable is an array
Removes elements from the array
Sorts the elements of an array
19.
How can you find the maximum value in an array in JavaScript?
max(array)
array.max()
Math.max(...array)
array.maximum()
20.
Given the array `var numbers = [1, 2, 3];`, what is the result of `numbers.reduce((acc, val) => acc + val, 0)`?
5
1
6
0