Q:

List of BLE devices being duplicated

Hi so currently I'm working on a Ionic project called BLE Scanner. I was struggling to find a solution and finally managed to connect to those devices. Here are the code that I found on the internet:
home.ts (just ignore the DetailPage)
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BLE } from '@ionic-native/ble';
import { DevicePage } from '../device/device';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  devices: any[];
  isScanning:boolean;

  constructor(public navCtrl: NavController,
              private ble: BLE) {
    this.devices=[];
    this.isScanning =false;
  }

  startScanning(){
    console.log("Scanning ..");
    this.devices=[];
    this.isScanning=true;
    this.ble.startScan([]).subscribe(
      device => {
        this.devices.push(device);
      }
    );

    setTimeout(() => {
      this.ble.stopScan().then(() => {
      console.log("Scanning has stopped");
      console.log(JSON.stringify(this.devices))
      this.isScanning = false;
      });
      }, 5000);
  }

  connectToDevice(device){
    console.log("Connect To Device");
    console.log(JSON.stringify(this.devices));
    this.navCtrl.push(DevicePage, {
      device: device
    });
  }
}

and home.html
<ion-content>
  <ion-list inset>
    <ion-item-sliding *ngFor="let device of devices">
      <button ion-item (click)="connectToDevice(device)">
        <h2>Device: {{ device.name }}</h2>
        <p>ID: {{ device.id }}</p>
        <p>RRSI: {{ device.rssi }}</p>
      </button>
    </ion-item-sliding>
  </ion-list>
  <ion-spinner *ngIf="isScanning==true" name="circles"></ion-spinner>
</ion-content>

So here comes a problem: The list of BLE devices is being duplicated because of the RSSIs keep fluctuating and I don't know how to show each device only once while its RSSI is being update continuously.
Here is my current app, as you can see there's only 1 device called RADUSB but being shown multiple times 
my current app
Please help me figure out the way to solve this problem. I appreciate every advice. Thank you!

A:

You are inserting into the list in startScan. Add a check to see if it already contains the device.
this.ble.startScan([]).subscribe(
      device => {
        if(this.devices.findIndex((dev:any)=>dev.id===device.id)==-1)
            this.devices.push(device);
      });

