let queue = ['first', 'second', 'third'];
queue.shift();
JavaScript Arrays and Looping Quiz
Want to learn more than this quiz offers you? Have a look at my Frontend web
development courses.
Create an account and save your quiz results
Login and save your results
OR
Question 1/5
What does the 'shift' method do to an array?
let queue = ['first', 'second', 'third'];
queue.shift();
Select your answer
Question 2/5
How can you create an array from a string?
let str = 'hello';
let arr = Array.from(str);
Select your answer
Question 3/5
How do you loop over all the elements of an array using a 'forEach' method?
let fruits = ['apple', 'banana', 'orange'];
fruits.forEach(function(item) {
console.log(item);
});
Select your answer
Question 4/5
What will be the output of this code?
let numbers = [10, 20, 30];
let sum = 0;
numbers.forEach(function(num) {
sum += num;
});
console.log(sum);
Select your answer
Question 5/5
What is the result of calling the method 'push' on a JavaScript array?
let fruits = ['apple', 'banana'];
fruits.push('orange');
Select your answer
Your Results
You did not answer any questions correctly.
Your Answers
Question 1/5
😊 Your
answer was correct
🙁 Your
answer was incorrect
What does the 'shift' method do to an array?
Available answers
The 'shift' method removes the first element from an array and returns that removed element. After 'queue.shift()', 'queue' becomes ['second', 'third'].
Question 2/5
😊 Your
answer was correct
🙁 Your
answer was incorrect
How can you create an array from a string?
let str = 'hello';
let arr = Array.from(str);
Available answers
The 'Array.from()' method creates a new, shallow-copied array instance from an array-like or iterable object. In this case, it turns the string 'hello' into ['h', 'e', 'l', 'l', 'o'].
Question 3/5
😊 Your
answer was correct
🙁 Your
answer was incorrect
How do you loop over all the elements of an array using a 'forEach' method?
let fruits = ['apple', 'banana', 'orange'];
fruits.forEach(function(item) {
console.log(item);
});
Available answers
The 'forEach' method executes a provided function once for each array element. In the provided code snippet, each item in the 'fruits' array is logged to the console individually.
Question 4/5
😊 Your
answer was correct
🙁 Your
answer was incorrect
What will be the output of this code?
let numbers = [10, 20, 30];
let sum = 0;
numbers.forEach(function(num) {
sum += num;
});
console.log(sum);
Available answers
The 'forEach' method loops through each number in the 'numbers' array, adding each to 'sum'. Therefore, 10 + 20 + 30 equals 60. The result logged is 60.
Question 5/5
😊 Your
answer was correct
🙁 Your
answer was incorrect
What is the result of calling the method 'push' on a JavaScript array?
let fruits = ['apple', 'banana'];
fruits.push('orange');
Available answers
The 'push' method adds one or more elements to the end of an array and returns the new length of the array. After calling 'fruits.push('orange')', 'fruits' becomes ['apple', 'banana', 'orange'].