vendredi 27 février 2015

Filter array by string length in javascript


I'm a really beginner in javascript


I have an array containing



array_1 = ["the","quick","brown","fox","jumped","over","the","lazy","dog"]


And I want another array but only with words that have length > 3



array_cleaned = ["quick","brown","jumped","lazy"]


How it is currently implemented:





array_1 = ["the","quick","brown","fox","jumped","over","the","lazy","dog"]

array_clean = [];
for(var i=0; i<array_1.length; i++){
if(array_1[i].length > 3)
array_clean.push(array_1[i]);
}

document.write(array_clean)



But I'm looking for a way to actually filter it. Any ideas?





Aucun commentaire:

Enregistrer un commentaire