DEV Community

Areeba Farooq
Areeba Farooq

Posted on

𝟰 𝗺𝗮𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗺𝗲𝘁𝗵𝗼𝗱𝘀 𝘁𝗼 𝗿𝗲𝗺𝗼𝘃𝗲 𝗲𝗹𝗲𝗺𝗲𝗻𝘁𝘀 𝗶𝗻 𝘁𝗵𝗲 𝗮𝗿𝗿𝗮𝘆,🚀

🚀 𝟰 𝗺𝗮𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗺𝗲𝘁𝗵𝗼𝗱𝘀 𝘁𝗼 𝗿𝗲𝗺𝗼𝘃𝗲 𝗲𝗹𝗲𝗺𝗲𝗻𝘁𝘀 𝗶𝗻 𝘁𝗵𝗲 𝗮𝗿𝗿𝗮𝘆:

  1. 𝗽𝗼𝗽 -Removes from the end of an Array.

  2. 𝘀𝗵𝗶𝗳𝘁 - Removes from the beginning of Array.

  3. 𝘀𝗽𝗹𝗶𝗰𝗲 -removes from a specific array Index.

  4. 𝗳𝗶𝗹𝘁𝗲𝗿 -allows you to programmatically remove elements from array.


but here I'm going to look at two most used methods
splice and filter.

- Splice():

when you use a splice, you need to find the index to the array element you want to remove using indexOf() and then remove that index with splice.

The splice () method changes the contents of an array by removing the existing element

array.splice((array).index0f(element_To_be _removed),1)


- filter ():

here is the code for the filter

myArray.filter(obj => obj !== myobject)

anyone who wants to explain more how filters work, you can share in the comment section

Top comments (0)