Search code examples
arraysangularngrx-store

dealing 2 arrays to 1 array in angular ngrx store?


I have two arrays a=[a,b,c] and b =[x,y,z] saved in the ngrx store as store=[a,b,c,x,y,z]. my problem is I have to delete the element in store array based on the index number only.

example: if I have to delete 'y' i'm getting an index number of y i.e: 2 but the index in store array has b.

please I need help in this scenario.


Solution

  • In this case I would fetch the value of the initial array and fetch the index through the value in the array store to delete it.

    something like:

    let value = b[idx] //idx is the position you get'it
    let index = store.indexOf(value);
    if (index !== -1) {
      array.splice(index, 1);
    }
    

    Other way is to passing the value directly instead of passing the index, in this case ignore the first line, which I think is easier, .