Find item index in angular

I have delete function which will emit then socket update other party items list and remove this item (replace static text) the problem is when I receive socket data I cannot find match item to update it.


  1. User 1 delete message
  2. User 2 get (static text) such as this message was deleted


  1. User 1 delete message (works)
  2. Message gets deleted for User 1 (works)
  3. gets inform of this delete (works)
  4. User 2 gets deleted message data from (works)
  5. find and replace deleted message (not work)


User 1 delete message

async presentPopover(ev: any, indexOfelement: any, own: any) {

    // send clicked item data to popover (popover will delete it and send back results)
    const popover = await this.popoverController.create({
      component: MessagesComponent,
      cssClass: 'my-custom-class',
      event: ev,
      componentProps: { id: ev, index: indexOfelement, from: 'pchat', own },
      translucent: true

    // returned results from popover
    popover.onDidDismiss().then((result: object) => {
      console.log('res2021 1: ', result);
      console.log(' 2: ',;
      if (result['data']) {
          this.socket.emit('messageDelete', { message: result['data'] }); // data is "id: 187, index: 15"
['data'].index, 1); // remove message from user 1 list (prefered if replace the text as well here instead of removing it)
    return await popover.present();


// delete message (in popover)
Pdelete(event) {
    this.privateChatsService.deleteMessage(this.navParams.get('id')).subscribe((res: any) => {
        this.popoverController.dismiss({ id: this.navParams.get('id'), index: this.navParams.get('index') }); //send back data

User 2 gets update about deleted message

async ngOnInit() {
    // remove deleted message
    this.socket.fromEvent('messDel').subscribe(async (message: any) => {
        console.log('from del emit in private chat: ', message); // data is "id: 187, index: 15", 1); // make changes in deleted item ("index" cannot be found)
    // end of

Note: Problem is in, 1); code where socket cannot find correct item based on the index the rest is working just fine.

Source: Angular Questions