Skip to content

Instantly share code, notes, and snippets.

@Kamilnaja
Last active August 17, 2019 07:28
Show Gist options
  • Save Kamilnaja/fec48e6dbad631112677ea94ce10896c to your computer and use it in GitHub Desktop.
Save Kamilnaja/fec48e6dbad631112677ea94ce10896c to your computer and use it in GitHub Desktop.
// I think, that this is an interesting answer. Check if object key exists, if yes, double
const columns = [
{ name: 'one', title: 'Order Number', id: 1 },
{ name: 'two', title: 'Strawberry', id: 2 },
{ name: 'three', title: 'Vanilla', id: 3 }
];
const mapped = columns.map(
item => item.id ? item.id = item.id * 2 : item
)
console.log(columns);
// But it can be done better
const mapped = objArr.map(item => {
item.id = item.id * 2;
return item;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment