W3Schools Documentation Array Map
fetch("https://jsonplaceholder.typicode.com/todos")
.then((response) => response.json())
.then((todos) => {
// This will mutate the original
const newArr = todos.map((a, i) => {
a.title = `Revised title ${i}`;
return a;
});
todos[1].title = "test test New";
todos.shift();
console.log(todos);
console.log(newArr);
// This Does Not mutate the original
const newArr = todos.map((a, i) => ({...a, title: `Revised title ${i}`}));
todos[1].title = "test test New";
todos.shift();
console.log(todos);
console.log(newArr);
});