Deep Dive into Data structures using Javascript — Arrays

What is an array?

Anatomy of an array

array-anatomy

Arrays in Javascript and other languages

What is the difference between Static and Dynamic Arrays?

// C++ — Initializing a static arrayint myNumbers [5] = { 16, 2, 77, 40, 12071 };

Data types that an Array can hold between different languages

When and when not to use an array in Javascript?

array-big-o

Why insert & delete operations works better at the end of an array

// INSERTION AT THE BEGINNING
const array1 = [ ‘a’, ‘b’, ‘c’ ]
array1.unshift(‘z’)console.log(array1) // => Output: [‘z’, ‘a’, ‘b’, ‘c’]// Now the indexes of ‘a’, ‘b’ and ‘c’ have changed from 0, 1, 2 to 1, 2, 3 respectively// DELETION AT THE BEGINNING
const array2 = [ ‘a’, ‘b’, ‘c’ ]
const firstElement = array2.shift()console.log(firstElement) // => Output: ‘a’
console.log(array2) // => Output: [‘b’, ‘c’]
// Now the indexes of ‘b’ and ‘c’ have changed from 1, 2 to 0, 1 respectively
// INSERTION AT THE END
const array1 = [ ‘a’, ‘b’, ‘c’ ]
array1.push(‘z’)console.log(array1) // => Output: [‘a’, ‘b’, ‘c’, ‘z’]// No changes on indexes for previous elements// DELETION AT THE END
const array2 = [ ‘a’, ‘b’, ‘c’ ]
const lastElement = array2.pop()console.log(lastElement) // => Output: ‘c’
console.log(array2) // => Output: [‘a’, ‘b’]
// No changes on indexes for previous elements

Mutable and Immutable Array methods in Javascript

const namesAscending = [‘a’, ‘b’, ‘c’]
const namesDescending = namesAscending.reverse()
console.log(namesDescending) // OUTPUT => [‘c’, ‘b’, ‘a’]
console.log(namesAscending) // OUTPUT => [‘c’, ‘b’, ‘a’]
const namesAscending = [‘a’, ‘b’, ‘c’]
const namesDescending = […namesAscending].reverse()
console.log(namesDescending) // OUTPUT => [‘c’, ‘b’, ‘a’]
console.log(namesAscending) // OUTPUT => [‘a’, ‘b’, ‘c’]

Mutable Array Methods:

Immutable Array Methods

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Şahin Arslan

Full stack web developer. I enjoy transforming complexity into simplicity.