Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to replace array element in javascript without mutation

function replaceAt(array, index, value) {
  const ret = array.slice(0);
  ret[index] = value;
  return ret;
}
const newArray = replaceAt(items, index, "J");

Source by www.peterbe.com #
 
PREVIOUS NEXT
Tagged: #replace #array #element #javascript #mutation
ADD COMMENT
Topic
Name
1+7 =