curriculum/challenges/english/blocks/quiz-javascript-arrays/66edcccbba6dacdb65a59067.md
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
What will be the output for the following code?
const numbers = [1, 2, 3];
console.log(numbers[10]);
[1, 2, 3]
null
10
undefined
Which of the following is the correct way to access the string "Jessica" from the developers array?
const developers = ["Jessica", "Naomi", "Tom"];
developers[1]
const developers = ["Jessica", "Naomi", "Tom"];
developers[2]
const developers = ["Jessica", "Naomi", "Tom"];
developers[-1]
const developers = ["Jessica", "Naomi", "Tom"];
developers[0]
What value will be assigned to the index variable?
const numbers = [10, 20, 30, 40];
const index = numbers.indexOf(20);
console.log(index);
2
3
-1
1
What does the rest syntax do?
It is used to divide a string into an array of substrings.
It is used to add or remove elements from any position in an array.
It is used to add elements to the end of the array and will return the new length.
It captures the remaining elements of an array into a new array.
What is array destructuring?
It is used to concatenate all of the elements of an array into a single string.
It is used to check if an array contains a specific value.
It is used to remove the last element from an array and will return that removed element.
It is used to extract values from arrays and assign them to variables in a more concise and readable way.
What value will be assigned to the arr2 variable?
const arr1 = [1, 2, 3];
const arr2 = [...arr1, 4, 5];
console.log(arr2);
[4, 5, 1, 2, 3]
[1, 2, [3, 4, 5]]
[1, 2, 3]
[1, 2, 3, 4, 5]
What will this code log to the console?
const colors = ["red", "blue", "green", "yellow"];
colors.splice(1, 2, "purple");
console.log(colors);
["red", "blue", "green", "yellow"]
["red", "blue", "yellow"]
["red", "yellow"]
["red", "purple", "yellow"]
What value will be assigned to the slicedArr variable?
const arr = ["apple", "banana", "cherry", "date"];
const slicedArr = arr.slice(1, 3);
console.log(slicedArr);
["apple", "banana"]
["cherry", "date"]
["apple", "cherry"]
["banana", "cherry"]
Which method returns the first index of a given element in an array?
firstIndex()
lastIndex()
searchIndex()
indexOf()
Which method is used to remove the first element from an array and returns that removed element?
pop()
slice()
splice()
shift()
What does the concat() method do?
Joins array elements into a string.
Adds an element to the beginning of an array.
Removes an element from the array.
Merges two arrays into a new array.
What will be the output of this code?
const fruits = ["apple", "banana", "cherry", "apple", "orange"];
fruits.splice(0, 1);
console.log(fruits);
["apple", "banana", "cherry", "apple", "orange"]
["apple", "banana", "cherry"]
["cherry", 'apple']
["banana", "cherry", "apple", "orange"]
What does the includes() method do?
It is used to divide a string into an array of substrings.
It is used to concatenate all of the elements of an array into a single string.
It is used to add or remove elements from any position in an array.
It is used to check if an array contains a specific value.
Which of the following methods is used to reverse an array in place?
reversed()
reverseArr()
reversing()
reverse()
What is a two dimensional array?
An array that only contains object literals.
An array of fixed length.
An array of floating point numbers.
An array of arrays.
Which of the following is true about the indexOf() method in arrays?
It always returns the last occurrence of the element.
It throws an error if the element is not found.
It requires the array to be sorted.
It returns -1 if the element is not found.
Which of the following is NOT an array method?
includes()
pop()
push()
trim()
What will be the output for the following code?
const arr = ["o", "l", "l", "e", "h"];
console.log(arr.join(""));
["o", "l", "l", "e", "h"]
"hello"
undefined
"olleh"
What will be the result of using the shift() method on an empty array?
TypeError
[]
null
undefined
Which method will return a new array without changing the original array?
shift()
pop()
push()
slice()