samedi 13 novembre 2021

Write a function that takes an array of objects and removes all red-colored foods from the original array (JavaScript) [duplicate]

array, foods = [{ name: 'Apple', color: 'red' }, { name: 'Egg', color: 'white' }]; and here's what I tried,

let foods = [{ name: 'Apple', color: 'red' }, { name: 'Egg', color: 'white' }];

            function removeRed(food) {
                food.filter(function (x) {
                    if (x.color !== 'red') {
                        return true;
                    } else {
                        return false;
                    }
                });
                return foods;

When I call the function like " removeRed(foods) " the output is giving both of the property-value pairs in my array. I'm a beginner student and this is my first Question here. Hope that someone answers :'D }

Aucun commentaire:

Enregistrer un commentaire