Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
105
rated 0 times [  109] [ 4]  / answers: 1 / hits: 19520  / 10 Years ago, tue, september 2, 2014, 12:00:00

I want to remove values from using less than and greater than condition for example my array is


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

so now my minimum value is 120 and maximum value is 130. I want to remove all the remaining elements from the array. Is this possible in javascript.


I am newbie so any help would be appreciated.


More From » javascript

 Answers
51

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.


[#69588] Friday, August 29, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaia

Total Points: 574
Total Questions: 109
Total Answers: 110

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
;