pratik lochawala
we web developers

we web developers

Remove continues element from an array

pratik lochawala's photo
pratik lochawala
ยทJun 29, 2021ยท

1 min read

Subscribe to my newsletter and never miss my upcoming articles

let's first understand what continuous element

remove-continues-element

in the above example, you have seen there is a repeating now I want to remove all continuous value only (not duplication) and keep 1st element of each repeating value

let's see how can we achieve that

we can achieve that using array filter method

Javascript filter accept callback function and that callback function accept 3 arguments

  • element: it's return an current element
  • index(optional): it's return index current element
  • array(optional): it's return actual array on which filter is perform

Remove continues element from an array

so in above code we first check if element index is 0 or current element is not match with previous element then we return that element

Wrapping up!

Share this blog with your friends ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿคโ€๐Ÿง‘๐Ÿผ and developers ๐Ÿ‘จโ€๐Ÿ’ป you know and let them know about these

Your feedback and comments are very important to me. ๐Ÿ’Œ

Get in touch ๐Ÿคœ๐Ÿค›

Instagram

YouTube

ย 
Share this