[Javascript] Array.prototype.with Immutable replace element inside array

Intro to Array.prototype.with(index, value)

const ages = [10, 15, 20, 25];

const newAges = ages.with(1, 16);
console.log(newAges); // [10, 16, 20, 25]
console.log(ages); // [10, 15, 20, 25] (unchanged)

 

posted @ 2024-03-26 15:28  Zhentiw  阅读(2)  评论(0编辑  收藏  举报