Skip to content

Instantly share code, notes, and snippets.

@ancyrweb
Last active January 12, 2022 02:09
Show Gist options
  • Save ancyrweb/6f0a7f80434a7aa87f012bdf81205d52 to your computer and use it in GitHub Desktop.
Save ancyrweb/6f0a7f80434a7aa87f012bdf81205d52 to your computer and use it in GitHub Desktop.
const users = [
{
name: "Jane",
balance: 100,
},
{
name: "John",
balance: 75,
},
{
name: "Ellis",
balance: 31.3,
},
];
const double = (amount) => amount * 2;
const indexToUpdate = 1; // we will change user at index 1 only
const nextUsers = users.map((user, index) =>
index === indexToUpdate ? { ...user, balance: double(user.balance) } : user
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment