ARRAY
Array in JavaScript
- An array is used to store multiple values in one variable.
- An array can store different types of values.
- Array values are written inside
[]. - Each value has an index number starting from
0. - We can use array methods to add, remove, and manage values.
Example :
let Flowers = [" Rose", "Loutus", "Lily"];
console.log(Flowers);
Outout;
[' Rose', 'Loutus', 'Lily']
0: " Rose"
1: "Loutus"
2: "Lily"
length: 3
Push
push() – last-la add
let a = [1, 2, 3];
a.push(4);
console.log(a);
Output:
[1, 2, 3, 4]
pop
pop() – last value remove
let a = [1, 2, 3];
a.pop();
console.log(a);
Output:
[1, 2]
Unshift
unshift() – first-la add
let a = [2, 3];
a.unshift(1);
console.log(a);
Output:
[1, 2, 3]
shift
shift() – first value remove
let a = [1, 2, 3];
a.shift();
console.log(a);
Output:
[2, 3]
ALL ARRAYS METHODS
push → add last
pop → remove last
unshift → add first
shift → remove first
includes → check value
indexOf → find position
slice → copy part
splice → add/remove
join → array to string
reverse → reverse
sort → arrange
forEach → print/do for each
map → change values
filter → select values
find → find first value
some → any one
every → all

Top comments (0)