immutable javascript array operations

Removing by filtering (returns a shallow copy of the array)

https://stackoverflow.com/questions/27396698/js-remove-element-from-array-without-change-the-original

function removeByIndex(array, index) {
  return array.filter(function (el, i) {
    return index !== i;
  });
}

Appending via concat

https://lorenstewart.me/2017/01/22/javascript-array-methods-mutating-vs-non-mutating/


const arr1 = ['a', 'b', 'c', 'd', 'e'];

const arr2 = arr1.concat('f'); // ['a', 'b', 'c', 'd', 'e', 'f']
console.log(arr1); // ['a', 'b', 'c', 'd', 'e']