DEV Community

Anandhi P
Anandhi P

Posted on

ARRAY IN JAVASCRIPT

ARRAY

Array in JavaScript

  1. An array is used to store multiple values in one variable.
  2. An array can store different types of values.
  3. Array values are written inside [].
  4. Each value has an index number starting from 0.
  5. 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)