I have been practicing some coding after some break. I’m trying to filter an array of objects from an api and creating a function the which will return me every word from the title of the fetch I’m making the request.
However, when I want to do the filter it shows that filter method is not recognized, and I don’t know if its affected if you are filtering an array that you called from an api.
This is the code.
function titles(word){
let sentence
let array = []
let api = 'https://jsonplaceholder.typicode.com/posts'
let data = fetch(api)
let response = data.then(res => res.json()).then(data => data.map((e) => { e.title}))
array = array.concat(response)
sentence = Promise.all(array.flat()).then(results => results.flat())
const people = sentence.filter(e => e.title.includes(word))
return people
}
However, returns an error message (see image)
But when I do the same on an array of objects the filter works well.
I appreciate any help, feedback and code improvement. Thanks in advance!