How to use create new array from other array with all elements that pass a condition with Array.filter() in JavaScript

1 Answer

0 votes
function isBigThen100(value) {
  return value >= 100;
}

var arr = [320, 9, 20, 190, 599]

var filtered_arr = arr.filter(isBigThen100);

for (i = 0; i < filtered_arr.length; i++)
  document.write("arr[" + i + "] = " + filtered_arr[i] + "<br />"); 
  

  
/*
run:  
 
arr[0] = 320
arr[1] = 190
arr[2] = 599
  
*/

 



answered May 21, 2016 by avibootz
...