0

I have an array of objects. I want to loop over the array of objects and add a new item to each object in the array as seen below. This works as desired. However, es-lint is displeased and throws the following: "Assignment to property of function parameter 'dataRow'" Here is the description. My question is this. Is there a better way to do this. I am aware I can disable the rule. However, that is not best practice, which is what I am looking for here.

  data.forEach((dataRow) => {
    if (dataRow.title === 'Some title') {
      dataRow.isDisplayed = displayValue;
    }
    if (dataRow.title === 'Some other title') {
      dataRow.isDisplayed = displayValue;
    }
  });
00robinette
  • 497
  • 5
  • 16
  • 2
    Does this answer your question? [How to avoid no-param-reassign when setting a property on a DOM object](https://stackoverflow.com/questions/35637770/how-to-avoid-no-param-reassign-when-setting-a-property-on-a-dom-object) –  Jun 21 '21 at 21:55
  • @BrunoSdoukos see my update. I am not looking to disable the rule as this is definitely not best practice. Thanks. – 00robinette Jun 21 '21 at 22:07
  • Please, don't read just the first answer for the indicated question. It has other answers which show how you can solve your problem without disabling the rule. –  Jun 21 '21 at 22:11

0 Answers0