Skip to content

Instantly share code, notes, and snippets.

@sagrawal31
Created September 30, 2021 18:13
Show Gist options
  • Save sagrawal31/4c5b15f6b1757a835ee34310febeb42d to your computer and use it in GitHub Desktop.
Save sagrawal31/4c5b15f6b1757a835ee34310febeb42d to your computer and use it in GitHub Desktop.
const urls: string[] = [];
const gallery = [
{id: 1, url: 'http://example.com/1.png'},
{id: 2, url: 'http://example.com/2.png'}
];
// Long code
gallery.forEach((item) => {
urls.push(item.url);
});
// Short code
urls.push(...gallery.map(item => item.url));
// "...” Spreat operator in JavaScript/TypeScript
// “map” function in JavaScript/TypeScript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment