I am trying to experiment around destructuring assignment. Now I have a case which I trying to cop up with destructuring itself.
For example, I have an input like th
If you don't mind using lodash
, you can try this:
import { mapValues } from 'lodash';
const input = {latitude: "17.0009", longitude: "82.2108"}
const {latitude, longitude} = mapValues(input, Number);
You could destructure the values, take an array of the values and map the a new data type of the value and assign this values back to the variables.
let input = { latitude: "17.0009", longitude: "82.2108" },
{ latitude, longitude} = input;
[latitude, longitude] = [latitude, longitude].map(Number);
console.log(typeof latitude, latitude);
console.log(typeof longitude, longitude);