We just made this code based on guesswork, and it worked. I am sure this is acceptable. I just want to make sure:
const state = { inProgress: true }
const actions = 'COMPLETE_RICE'
const change = { inProgress: false, rice: 'cooked' }
const {
0: newState,
1: newActions,
2: newChange,
} = [state, actions, change]
console.log('New State:', newState)
console.log('New Actions:', newActions)
console.log('New Change:', newChange)
Run codeHide resultIs there a better way to do this?
Any problems or violations?
I can not find any examples of this and only tried because I recalled that:
['one', 'two', 'three'] can be expressed as an object:
{
0: 'one',
1: 'two',
2: 'three'
}
Itβs not exactly specified here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
But it works.
source
share