Announcement

Collapse
No announcement yet.

remove empty elements from an array in Javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • remove empty elements from an array in Javascript

    remove empty elements from an array in Javascript

    example:

    Code:
    const arr = [1,2,3,"",4,5,""]

  • #2
    the array filter method will solve this problem

    Code:
    const arr = [1,2,3,"",4,5,""]
    arr.filter(a=>a !== "")
    Click image for larger version

Name:	Screenshot 2021-09-29 at 2.46.08 PM.png
Views:	30
Size:	16.8 KB
ID:	894

    Comment


    • #3
      mani without any expression filter method will remove the empty values,



      For Example:

      HTML Code:
      const arr = [1,2,3,"",4,5,""]
      arr.filter(a=>a)

      Comment

      Related Topics

      Collapse

      Working...
      X