How to update array immutably in JavaScript

Arrays
By Jad Joubran · 
Last updated Feb 28, 2024
const names = ["Alex", "Sam", "Blane"];

const newNames = names.with(1, "Sammy");
// names remains unmodified
console.log(newNames);
["Alex", "Sammy", "Blane"]
Array.with on web.dev