-3

I'd like to remove duplicate arrays in javascript from this array: In this case i wish to remove the blue color

var fruits = [
                {
                    'color':'red',
                    'name': 'redName'
                },
                {
                    'color':'blue',
                    'name': 'blueName'
                },
                {
                    'color':'blue',
                    'name': 'blueName'
                    },
                {
                    'color':'yellow',
                    'name': 'yellowName'
                },
             ];

        for(let i=0; i < fruits.length; i++)
          {
           if(indexOf(fruits[i]) == -1)
           newarray.push(fruits[i]);
          }
        console.log(newarray);
  • 3
    Stack Overflow is not a free code writing service, please show your code/effort and what the actual problem is. Also, removing duplicates from an array is a issue that's been solved a thousand times before. Please do some research before asking a question on SO. – Cerbrus Oct 26 '17 at 14:05
  • Please try and edit this into a [Minimal, complete verifiable example](https://stackoverflow.com/help/mcve), it might be helpful for you to look at [how to ask a successful question](https://stackoverflow.com/help/how-to-ask). In this particular case you would be well served to try and use a search platform to find your solution as this question has been answered elsewhere. – D Lowther Oct 26 '17 at 14:08

1 Answers1

2

Try this:

    var newArray = fruits.filter(x => x.color !== 'blue');

    console.log(newArray);
assembler
  • 3,098
  • 12
  • 43
  • 84