How to remove array values using condition less than and greater than in javascript

Sure, just filter the array

var arr = [
    138,124,128,126,140,113,102,128,136,110,134,132,130,132,132,104,116,135,120
]

var new_arr = arr.filter(function(x) {
    return x > 120 && x < 130;
});

FIDDLE

Use >= and <= to include 120 and 130 as well etc.


using map as below,

$.map(a,function(o,i){  if(o < 130 && o > 120) return o; })

Simply use filter, it's created for things like this, the code below should do the job as you want:

//ES6
var arr = [138,124,128,126,140,113,102,128,136,110,134,132,130,132,132,104,116,135,120];
var filteredArr = arr.filter(n => n>120 && n<130); //[124, 128, 126, 128]

Tags:

Javascript