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.

Expression:

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

Output:

[ -15, -8 ]

--

--