L
L
lavezzi12017-07-12 19:29:39
JavaScript
lavezzi1, 2017-07-12 19:29:39

How to avoid eslint no-param-reassign error in my case?

Hello. The logic is this, I need to update an element in the table, send the data to the server, get the new changed data and want to put it into an array to update it in the table.

this.itemsData.forEach((item) => {
   if (item.id === this.selectedItem.id) {
      item.name = newItem.name;
      item.data = newItem.data;
  }
});

Eslint swears that they say you can not reassign the data. And how then to change the data in array? What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2017-07-13
@lavezzi1

You are changing the item, and in the eslint settings it is forbidden.
For example I would do this

const item = this.itemsData.find(val => val.id === this.selectedItem.id);
if (item) {
  item.name = newItem.name;
  item.data = newItem.data;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question