The Wayback Machine - https://web.archive.org/web/20250402220228/https://www.geeksforgeeks.org/quizzes/javascript-arrays-1/

JavaScript Arrays

This section covers the questions for JavaScript Arrays to clear all your concepts.

Last Updated :
Discuss
Comments

Question 1

Which of the following statements creates a new empty array?

  • let arr = [ ];

  • let arr = new Array(0);

  • let arr = Array();

  • All of the above

Question 2

How do you access an element in an array?

  • By using curly braces { }

  • By using square brackets [ ]

  • By using parentheses ( )

  • By using angle brackets < >

Question 3

Which of the following array methods can be used to add one or more elements to the end of an array?

  • push()

  • pop()

  • shift()

  • unshift()

Question 4

What is the output of the following code snippet?

JavaScript
let arr1 = [1, 2, 3];
let arr2 = arr1;
arr2.push(4);
console.log(arr1);


  • [1, 2, 3]

  • [1, 2, 3, 4]

  • [2, 3, 4]

  • None of the above

Question 5

Which of the following array methods can be used to remove the last element from an array?

  • pop()

  • shift()

  • unshift()

  • splice()

Question 6

How do you loop through an array in JavaScript?
 

  • for (i = 0; i < arr.length; i++)

  • while (i < arr.length)

  • do while (i < arr.length)

  • for each (element in arr)

Question 7

Which of the following array methods can be used to remove one or more elements from an array and replace them with new elements?

  • splice()

  • slice()

  • concat()

  • push()

Question 8

What is the output of the following code snippet?

let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];
let arr3 = arr1.concat(arr2);
console.log(arr3);

  • [1, 2, 3, 4, 5, 6]

  • [4, 5, 6, 1, 2, 3]

  • [1, 4, 2, 5, 3, 6]

  • None of the above

Question 9

What is the output of the following code snippet?
const arr = ["apple", "banana", "orange"];
const newArr = arr.slice(1, 2);

console.log(newArr);

  • ["apple", "banana"]

  • ["banana", "orange"]

  • ["banana"]

  • ["orange"]

Question 10

What is the difference between slice() and splice() array methods?

  • slice() creates a new array, while splice() modifies the original array.

  • splice() creates a new array, while slice() modifies the original array.

  • slice() removes elements from the beginning of the array, while splice() removes elements from the end of the array.

  • splice() adds elements to the beginning of the array, while slice() adds elements to the end of the array.

Ready to go from coding beginner to development pro? Our DSA to Development Coding Guide has everything you need to crush coding interviews and ace real-world projects! Limited spots available!

There are 10 questions to complete.

Take a part in the ongoing discussion