Node JS Filter Negative Numbers From The Array

Node.JS (JavaScript) Filter Negative Numbers From The Array

We hope you already know the filter, map and reduce

  1. filter (Extract subset of the array)
  2. map (To iterate array)
  3. reduce ( To get single value from the array i.e sum of the array)

Following Example demonstrate how to extract the negative integers or numbers from the array using Javascript, Node.JS

In the example, We have used filter to extract the negative numbers.


negativeNumbers = numbers.filter(n => n <0);

If n is less than 0 it will return you the filter array [ -15, -8 ]

if you run the following example you will get


[ -15, -8 ]

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like