Say, I have an object
const range = { min: '10', max: '20' }
And I want to destructure it so that after that I have 2 variables:
- min with the value of 10 (not string '10'), and
- max with the value of 20
const { min, max } = range will only result to min with the value of '10' (not 10). What I want is the Number(10)
How could I do that? I did know a little bit about ES6 destructuring and did some research, tried different syntaxes but couldn't find a satisfied solution. Could anyone suggest one?
Conclude: There're very nice clever syntax in the answers below, but as to go with real code, I would just go with the more verbose but readable one:
const min = +range.min // or Number(range.min)
const max = -range.max // or Number(range.max)