-3

I have this in array:

[
    {item: "7621629-01/17-23", phoneNum: "032/406713"},
    {item: "7621629-01/17-24", phoneNum: "032/406713"},
    {item: "7621629-01/17-25", phoneNum: "032/406713"}
]

What i want is to remove all duplicates phoneNum and left only one. Any suggestion how can i do that? Its in .ts file. So to have object but to remove duplicate phoneNum because im using autocomplete and now in suggestion i get three same number

Sandy Gifford
  • 7,219
  • 3
  • 35
  • 65
uzhas
  • 895
  • 4
  • 13
  • 27
  • this is not array of objects and i dont want to use jquery – uzhas Sep 05 '17 at 15:56
  • From the existing array, create a new array that doesn't have duplicates. – Kevin B Sep 05 '17 at 16:00
  • @uzhas at that question sort by votes, you will find lots of solutions. Using Jquery, filter, etc.. If you don't like them just use a loop. And what you are showing are 3 objects..... – Òscar Raya Sep 05 '17 at 16:01

1 Answers1

-1

try to use a pipe like this

transform(items: Array<any>, args?: any): any {

        let filtredItems= [];

        if(Array.isArray(items) && items.length > 0)
          items.forEach((el) => { 
             if(filtredItems.indexOf(el) < 0) 
                filtredItems.push(el)  
          });

        return filtredItems;
}
Mahmoud
  • 868
  • 11
  • 27