How can I only filter to get 3 stories from an News API?

How can I only filter to get 3 stories from an News API?

after getting the response from the API, you can put it in an array then filter it to get the three stories you want from this array for example

const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);
// expected output: Array ["exuberant", "destruction", "present"]

this example is taken from MDN

1 Like

its either you want to filter it like @mohamedeliwa’s solution, or you want to get the first 3 which is like this

let list = ["a", "b", "c", "d"]

let tes = list.slice(0, 3)
1 Like