Manipulating arrays in JavaScript

in #palnet3 years ago (edited)

Today I learned about manipulating arrays in JavaScript. The exercise was taken from this site:

https://www.learn-js.org/en/Manipulating_Arrays

In the exercise I had to manipulate the array called myArray and do the following:

  1. Push the number 42 to the end of the array
  2. Shift a variable from the beginning of the array

After much trial and error I came up with this solution:

var myArray = [true, "What is the meaning of life?"];
myArray.push(42);
myArray.shift();
console.log(myArray[0]);
console.log(myArray[1]);
Sort:  

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!