The correct way to filter js array

// This is the array that you need to filter
const animals = ['elephant', 'tiger', 'cat', 'rhino'];

// This is the array with filtered results. This example code will filter elements which has more than 4 characters
const filtered_array = animals.filter(animal => animal.length > 4);

Leave a Reply

(*) Required, Your email will not be published