Skip to content

Instantly share code, notes, and snippets.

@ajyounguk
Last active February 13, 2019 14:37
Show Gist options
  • Save ajyounguk/3e49c848ec381e4e07d2b5129b56dd67 to your computer and use it in GitHub Desktop.
Save ajyounguk/3e49c848ec381e4e07d2b5129b56dd67 to your computer and use it in GitHub Desktop.
object and array splicing / object spread operator (...)
messages = {
1: {
id: '1',
text: 'This is a message',
userId: '1',
},
2: {
id: '2',
text: 'This is a message too',
userId: '2',
},
3: {
id: '2',
text: 'This is a message 3',
userId: '3',
},
}
const {
[2]: messsage,
...otherMessages
} = messages;
console.log('... messages ' + JSON.stringify(messages, null, 3))
console.log('... otherMessages ' + JSON.stringify(otherMessages, null, 3))
arr = [ 1,2,3 ]
arr.splice(2,1)
console.log('splice arr ' + JSON.stringify(arr, null, 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment