Mastering Arrays: Everything You Need to Know to Get Started
Array 101: The Absolute Beginner’s Guide to Data Structures

I have joined and started learning Software development with ChaiCode Web dev Cohort 2026 and very excited😊
In programming we need variable to store data . so we can access easily in another place just by variable name. suppose when you need to store five friend name then you have to create five separate variable . This is unnecessary because all belongs to same, your friend group .
To solve this problem , we used array . It is just storing values which are same in nature in one variable name. It has many benefits .
It provides collection in one variable name.
The items are easily accessible and update by using index.
Fast retrieval of data from memory .
There are a lot of methods to work with data.
Array stored data on order manner. so for ordered collection array is used
In JavaScript both array and object are of object type. The main difference is array stored data in ordered way so whenever ordered matter we use array.
// suppose i need to make super hero array
const superman = "Superman" ;
const ironMan = "Ironman" ;
const thor = "Thor" ;
const hulk = "HULK" ;
// this should be one collection
// when someone say 10 heroes , we have to make 10 variables
// so what is best array is best to store these type of data
const superHeroes = [superman, ironMan, thor, hulk];
console.log(superHeroes) ; // ['Superman', 'Ironman', 'Thor', 'HULK']
Ways of creating array
There are many ways of creating arrays in JavaScript .
first is Array Constructor and second is Array literal which is just [].
// ways of creating arrays
// 1. Array constructor
const friends = new Array("Sudip", "Akash", "Rakesh");
console.log(friends)
// by just Array
const fruits = Array("Mango", "Grapes", "Watermelon", "Litchi") ;
console.log(fruits)
// when one items add
const numbers = new Array(7)
console.log(numbers) // it create empty slot [empty × 7]
// 2. Array literal
const ourSirs = ["Hitesh", "Piyush", "Anirudh", "Akash"] ;
console.log(ourSirs) // ['Hitesh', 'Piyush', 'Anirudh', 'Akash']
Accessing and Updating Elements
Elements is members of array. It is ordered so It is 0 indexed. we can access by using index which is assign to each elements of array.
// Accesssing elements in array
const colors = ["red", "pink", "orange", "blue"] ;
// accessing first
colors[0] // red
// accessing last
colors[3] // blue
// every array has length property so we can used to find length
console.log(colors.length) // 4
colors[colors.length - 1] // last element accessing
for updating also same just access and update with new item .
// updating items in array
// change blue to green
colors[3] = "green"
console.log(colors) // (4) ['red', 'pink', 'orange', 'green']
Looping in Array
We need array to store group of data so that we can perform some operations on overall data easily . This is easily done by looping in array elements .
There are many looping methods available in JavaScript. They are :
// Looping in arrays
// baiscs for loop
for(let i = 0; i<colors.length; i++){
const upper = colors[i].toUpperCase() ;
// console.log(upper) ; // RED PINK ORANGE GREEN
}
// for of loop
// it is same as for loop but it doesnot need counter variable like for loop
for(let color of colors){
console.log(color) ;
}
// forEach
colors.forEach(function (color){
console.log(color) ;
})
How Array stored in JavaScript
We know that creating and storing of array is by reference in JavaScript. There are two memory callstack and heap memory . All primitives data are stored in callstack and Object type stored in hep memory . It is because Object are growing in nature. They can grow and shrink dynamically so It is stored in Heap memory and the variable are stored in callstack and it is pointing to the reference in heap memory .
when we give like about[5] = "Developer" it create empty slot in 4 index . The undefined is value in JavaScript which is default value of JavaScript if variable is not assign any value .
Summary
This is all about array and It is very much used and basics data structure in JavaScript . It is dynamic in nature. We can store different type of data in arrays and there is no issue. we can access many built in methods which make easy to work with array . The typeof array is object and when you create and store it in variable it is just reference stored in variable . so when we copy the reference only copy which point to same array or objects in JavaScript . so It is not actual copy of array.




