Arrays in JavaScript
In JavaScript arrays is a special type of object which contain order list of values. It is often used when we want to store list of elements and access them by a single variable.
- Way to declare array.
Example
let userIds = [1230, 234, 1278, 984, 763, 900];
Iterating over Arrays
- Two different way to iterate an array.
let numbers=[23, 123, 124, 765, 0]
// for loop
for(let i = 0; i< numbers.length; i++){
console.log(numbers[i])
}
// for..of loop
for(let number of numbers){
console.log(number)
}
Copy by Value and Reference
When you copy an object b = a both variables will point to the same address. This behavior is called copy by reference value. Strictly speaking in Ruby and JavaScript everything is copied by value. When it comes to objects though, the values happen to be the memory addresses of those objects