VisualJS

Arrays

Ordered collections. See how they store, access, and share data in memory.

What is an Array?

Ordered values in numbered positions.

const fruits = ["🍎", "🍌", "🍇"]
🍎
0
🍌
1
🍇
2

Indexes

Access any value by its position number.

fruits[
]
🍎
0
🍌
1
🍇
2

Length

How many items are in the array.

A
0
B
1
C
2
.length =3

Updating Values

Tap a slot to replace its value.

fruits[1] = "🥭"
🍎
0
🍌
1
🍇
2

Memory

Variables don't contain arrays — they point to them.

const fruits = ["🍎", "🍌", "🍇"]
fruits
heap
🍎
0
🍌
1
🍇
2

The variable holds a reference — a pointer to where the array lives in memory.

References

Two variables can point to the same array.

const a = ["🍎", "🍌"]
const b = a
a
b
🍎
🍌

Copy vs Reference

Spread creates a new array. Assignment shares the same one.

const a = [1, 2, 3]
const b = a          // reference
const c = [...a]     // copy
ab
1
2
3
shared
c
1
2
3
independent

Sparse Arrays

Arrays can have empty slots — holes with no value.

const arr = [1, , 3]
1
0
empty
1
3
2
.length = 3
arr[1] = undefined

Length Magic

Setting a distant index creates empty slots automatically.

const arr = []
arr[5] = "🚀"
[ ] empty

Explorer

Your sandbox — create, modify, copy, and reference.

myArr
heap
🍎
0
🍌
1
🍇
2
.length = 3