For example, I want to write something like:
const initial = [1, 2, 3, 4];
const indexIWantToChange = 2;
const obj = {
prop: () => {
const newArr = [...initial];
newArr[indexIWantToChange] = 'Something new';
return newArr;
}()
};
How to change one specific element in array by index without mutating the original array in a functional style? Is there a one-liner of this maybe?