DEV Community

A K I L A N
A K I L A N

Posted on

Basic array methods

Array length()

  • length returns the size of the array

  • we can also set the length of the array

Array tostring()

  • this returns the elements of an array as a coma separated string

Array at()

  • Return the value gien index value fruits.at(-2)

  • we using at() for negative ordersfruits.at(-2)

Array join()

  • this returns the same process like tostring but we set the separator

Array pop()

  • this removes the last elememts of the array

Array push()

  • this add a new elements at the last of an array

Array shift()

  • This remeove the first elements of an array

Array unshift()

  • this add thhe given elements in the first of the array

Changing Elements

  • we can changethe elemnts directly using index value

Array.isArray()

  • this check the given array is true or false

** Array delete()**

  • using delecte() leaves undefined at the value pop is prefered

Array concat()

  • in normal programming it concat to string but here it join two arrays

  • The concat() method does not change the existing arrays. It always returns a new array.

  • we can also add new elemnts using this

const arr1 = ["Emil", "Tobias", "Linus"];
const myChildren = arr1.concat("Peter"); 

Enter fullscreen mode Exit fullscreen mode

Array copyWithin() (TBD)

Array flat() (TBD)

  • this will remove the given brackets

*Array splice() *

  • The splice() method can be used to add new items to an array:

  • const fruits = ["Banana", "Orange", "Apple", "Mango"];
    fruits.splice(2, 0, "Lemon", "Kiwi");

  • 2 denotes the potion, 0 denote the value to remove

**The difference between the new toSpliced() method and the old splice() method is that the new method creates a new array, keeping the original array unchanged, while the old method altered the original array.**
Enter fullscreen mode Exit fullscreen mode

Array toSpliced()

Top comments (0)