Arrays I
1.
What will `Array.isArray([])` return?
undefined
FALSE
null
TRUE
2.
How can you add multiple elements to the beginning of an array?
unshift()
push()
prepend()
prependToStart()
3.
Which method is used to sort the elements of an array in JavaScript?
arrange()
order()
sort()
organize()
4.
What is the purpose of the `map` method in JavaScript arrays?
Removes elements from the array
Filters elements based on a condition
Adds new elements to the array
Transforms each element of the array
5.
What will the following code output: `console.log([1, 2, 3] + [4, 5, 6]);`?
1,2,34,5,6
10
123456
NaN
6.
How do you find the length of an array in JavaScript?
length()
size()
count()
arr.length
7.
What method is used to add elements to the end of an array in JavaScript?
pop()
push()
shift()
unshift()
8.
Which method is used to remove the last element from an array in JavaScript?
push()
pop()
shift()
unshift()
9.
What is the correct way to access the element at index 2 in the array 'arr'?
arr.at(2)
arr(2)
arr[2]
get(arr, 2)
10.
How do you check if a variable is an array in JavaScript?
isArrayVariable()
isArray()
typeofArray()
checkArray()
11.
What is the result of the following code: `['apple', 'banana', 'orange'].indexOf('banana')`?
0
1
2
-1
12.
Which method is used to join all elements of an array into a string?
concat()
join()
merge()
combine()
13.
How do you remove the first element from an array in JavaScript?
deleteFirst()
removeFirst()
shift()
splice()
14.
Given the array `var numbers = [1, 2, 3, 4, 5];`, what is the result of `numbers.slice(1, 3)`?
[2, 4]
[1, 2]
[2, 3]
[3, 4]
15.
What does the `splice()` method do in JavaScript?
Concatenates two arrays
Adds or removes elements from an array
Reverses the elements of an array
Sorts the elements of an array
16.
What is the purpose of the `forEach` method in JavaScript arrays?
Removes elements from the array
Adds a new element to the array
Iterates over each element of the array
Filters elements in the array
17.
What is the output of the following code: `['a', 'b', 'c'].reverse()`?
['c', 'b', 'a']
['a', 'b', 'c']
cba'
abc'
18.
What is the correct way to check if an element is present in an array?
exists()
contains()
includes()
find()
19.
Given the array `var fruits = ['apple', 'banana', 'orange'];`, how do you remove 'banana' from the array?
fruits.splice(1, 1)
fruits.remove('banana')
fruits.removeElement('banana')
fruits.pop('banana')
20.
What will the following code output: `Array.from('hello')`?
['h', 'e', 'l', 'l']
['hello']
hello'
['h', 'e', 'l', 'l', 'o']