Took 4 minutes 42 seconds to code JavaScript find() method that returns all elements of the array meeting a specific condition. Here is the code snippet.
Code:
arr = [18, 10, 65, 70];
function find(arr) {
var arr2 = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i] > 18) {
arr2.push(arr[i]);
}
}
return arr2;
}
var new_arr = find(arr);
document.write(new_arr);
Result:
65,70
No comments:
Post a Comment