[Vuejs]-Array don't change after splice and update its property

0👍

You should use the third param of forEach array to edit this array

this.globalError.testArray.forEach((item, i, myArray) => {
  if (item.index > indexSelected) {
      myArray[i].index -= 1;
  }
});

Or you can use .map

this.globalError.testArray = this.globalError.testArray.map(item => {
      if (item.index > indexSelected) {
          item.index -= 1;
      }
      return item;
    });

0👍

I have found the reason. The updating index item.index -= 1; triggered a function that unexpectedly reverse the array from the begining state.

Thanks for your help and sorry for this inconvenience.

Leave a comment