JavaScript Array Question 9

Introduction

What is the output of the following code?


let myArray = ["hello", "new", "world"];

myArray.length -= 1;//w  ww  .j ava 2s  . c  o  m

console.log( myArray.toString()); // hello,new

// Lets reset our array
myArray = ["hello", "new", "world"];

// Remove the last element
myArray.pop();

// Lets reset our array
console.log( myArray.toString()); // hello,new

myArray = ["hello", "new", "world"];

// Remove the first element
myArray.shift(); // returns "hello"

console.log( myArray.toString()); // "new,world"


hello,new
hello,new
new,world



PreviousNext

Related