Filter array by string length in javascript [duplicate]

You can use filter method:

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

const new_array = array_1.filter((element) => {
  return element.length > 3;
});

// OR refactor
// const new_array = array_1.filter( (element) => element.length > 3);

console.log(new_array)

// Output:
// ["quick", "brown", "jumped", "over", "lazy"]

Leave a Comment