How do I parse a string to number while destructuring?

前端 未结 8 1053
[愿得一人]
[愿得一人] 2020-12-05 10:23

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

8条回答
  •  时光取名叫无心
    2020-12-05 11:05

    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);

提交回复
热议问题