Angular2 JSON Duplication Deletion
<p>I am working with a large JSON file holding information about instructors at my school. I want to be able to pull all the teachers names from this list so I can then put them into Firebase. However, whenever I loop over my JSON file and try to filter out all the duplicate teacher names I still end up with duplicates even when I try to do a second round of deletion. The JSON looks like this:</p>

<pre><code>{
"Id": "1",
…
"Instructor": "name1, name2, name3", 
…
},
{
"Id": "2",
…
"Instructor": "name1", 
…
},
{
"Id": "3",
…
"Instructor": "name1, name2", 
…
}
</code></pre>

<p>As seen above sometimes there is just one name, other times there are multiple. I handle this though in my logic but no matter what I still end up with duplicates. If anyone can help me come up with a way to solve this it would be greatly appreciated. I'll add my code that I have already below.</p>

<pre><code>public remove_duplicates(arr: any[]): any[] {
    let output: any[] = [];
    for (let i = 0; i &lt; arr.length; i++) {
      let instruc: any[] = arr[i].Instructor.split(',');
      for (let j = 0; j &lt; instruc.length; j++) {
        let push: boolean = true;
        arr[i].Instructor = instruc[j];
        for (let k = 0; k &lt; output.length; k++) {
          let i1: string = output[k].Instructor;
          let i2: string = arr[i].Instructor;
          if (i1.trim().localeCompare(i2.trim()) == 0) {
            push = false;
          }
        }
        if (push)
          output.push(arr[i]);
      }
    }

    console.log(output.length);
    for (let k = 0; k &lt; output.length; k++) {
      for (let i = k + 1; i &lt; output.length; i++) {
        if (new String(output[i].Instructor).valueOf().trim()
          === new String(output[k].Instructor).valueOf().trim()) {
          output.splice(i, 1);
        }
      }
    }

    for (let k = 0; k &lt; output.length; k++) {
      console.log(output[k].Instructor);
    }

    console.log(output.length);
    return arr;
  }

  ngOnInit() {
    this.http.get('courses.json').take(1)
      .map((res: Response) =&gt; res.json())
      .subscribe(
      data =&gt; {
        this.list = data;
      },
      err =&gt; console.log(err),
      () =&gt; this.remove_duplicates(this.list)
      );
  }
</code></pre>