DEV Community

Saravanan Cn
Saravanan Cn

Posted on

Day 14: Learning JavaScript Array Methods πŸš€

Today i continued learning Javascript and explored several useful array methods.

1.length

the length property tells us how many elements are in an array.

let Laptops = ["Hp","lenovo","dell","orange"];
console.log(fruits.length);

2. toString()

Converts an array into a string.

console.log(fruits.toString());

3. join()

console.log(fruits.join(" - "));

4.delete()

The delete operator can remove an element from an array, but it leaves an empty space.

5. concat()

Combines two or more arrays.

`let a = ["Apple", "Banana"];
let b = ["Orange", "Mango"];

let result = a.concat(b);`

6. flat()

Converts a nested array into a flatter array.

`let numbers = [1, 2, [3, 4], [5, 6]];

console.log(numbers.flat());`

7. push()

Adds an element to the end of an array.

fruits.push("Mango");

8. unshift()

Adds an element to the beginning of an array.

fruits.unshift("Mango");

9. pop()

Removes the last element from an array.

fruits.pop();

10. shift()

Removes the first element from an array.

fruits.shift();

11. splice()

Used to add, remove, or replace elements in an array.

fruits.splice(1, 1);

12. slice()

Creates a new array containing a selected portion of an array.

let result = fruits.slice(1, 3);

13. copyWithin()

Copies part of an array to another position within the same array.
let numbers = [1, 2, 3, 4, 5];

numbers.copyWithin(2, 0);

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ •