I have an array of objects which will be send to my database. These objects are fetched from separate Api and some of them come back empty. Hoe do I check if an object within the array is empty and then remove that object.
I tried using a for loop to loop through the array of objects, but this ends up calling the post function several times and sending copies of the array to my database.
Promise.all(promises)
.then(values => {
for(let i = 0; i<= values.lenght; i++){
if(Object.keys(values[i]).lenght === 0){
values.splice(i, 1)
}else{postArray(values)}}})
.catch(err => console.log(err))
This posts the array multiple time and still doesn't work.
lenght!==length- is this just a typo? (twice)