Member-only story

Basic Data Structures: Arrays

Jay Wen
3 min readJul 8, 2020

--

While taking a udemy course for data structures and algorithms I have learned that there are many other types of data structures than the ones I’ve been using which are arrays and objects. There are arrays, objects/hashes, linked lists, stacks and queues, trees, and graphs. I’ll be doing a simple break down of each data structure starting with arrays.

Arrays are one of the simplest forms of data structures. Arrays can contain strings, numbers and booleans as well as a combination of different data types within the same array.

let array = [1, 2, 3, 4, 5]
let array2 = ['apples, 'oranges', 'watermelons']
let array3 = [5, 'pineapple', false ]

To find out how many items an array contains, you can do so by calling ‘.length’ on the array.

let array = [1, 2, 3, 4, 5]
array.length // 5
let array2 = ['apples, 'oranges', 'watermelons']
array2.length // 3

Array indexes begin from 0 and not 1. To access the data element inside the array, you can do it using the bracket notation:

let array = [1, 2, 3, 4, 5]
0 1 2 3 4
array[2] // 3let array2 = ['apples, 'oranges', 'watermelons']
0 1 2
array2[1] // 'oranges'let array3 = [5, 'pineapple', false ]
0 1 2
array3[0] // 5

--

--

Jay Wen
Jay Wen

Written by Jay Wen

Hey! I’m a full stack software engineer. Here’s where I document my technical learning and any tips/skills I can share as I continue to learn. :)

No responses yet