DEV Community

Cover image for LEVEL UP with JavaScript! LVL 8
DevCronin
DevCronin

Posted on

LEVEL UP with JavaScript! LVL 8

In this blog series tutorial, I will be covering some of the basic JavaScript programming concepts.

This is geared toward beginners and anyone looking to refresh their knowledge.

See the Previous Level Here

Level 8 will cover:

  • Accessing Multi-Dimensional Arrays With Indexes
  • Manipulating Arrays With Push()
  • Manipulating Arrays with Pop()
  • Manipulating Arrays With Shift()
  • Manipulating Arrays With Unshift()

Accessing Multi-Dimensional Arrays With Indexes

Multi-dimensional arrays can be referred to as an array of arrays.

Each set of brackets is a level where the outermost set of brackets are the first level.


let diceArray = [ 
  [18,5,1], 
  [6,10,20],
  [2,7,15], 
];

diceArray[1];

[6,10,20]

diceArray[1][1];

10

Enter fullscreen mode Exit fullscreen mode

Manipulating Arrays With Push()

The push method adds items to the end of an array.


let diceRoll = ["Roll D6", 4,5,2,6];

diceRoll.push(1,5);

console.log(diceRoll);

["Roll D6", 4,5,2,6,1,5]

Enter fullscreen mode Exit fullscreen mode

Manipulating Arrays with Pop()

Pop removes the last item from an array.


let moonBeam = [8,5,10];

let firstEnemy = moonBeam.pop();

console.log(firstEnemy);

10

console.log(moonBeam);

[8,5]

Enter fullscreen mode Exit fullscreen mode

Manipulating Arrays with shift()

Shift removes an item from the beginning of an array.


let moonBeam = [8,5,10];

let firstEnemy = moonBeam.shift();

console.log(firstEnemy);

8

console.log(moonBeam);

[5,10]

Enter fullscreen mode Exit fullscreen mode

Manipulating Arrays With Unshift()

The unshift method adds items to the beginning of an array.


let inventory = ["cloak", "magic ring", "long sword"];

inventory.unshift("gold coins");

console.log(inventory);

["gold coins", "cloak", "magic ring", "long sword"]


Enter fullscreen mode Exit fullscreen mode

Thank you for reading my blog! This is the eighth of my series on JavaScript so if you would like to read more, please follow!

Support and Buy me a Coffee

Discussion (0)