我想从jQuery中的数组对象中删除双引号 由 funde发布于 2020-05-18 07:59:11 javascriptjquery 收藏 let pos = { lat: "33.5896138", lng: "73.3885526" }; 我有这样的数组,但我想从latLng值中删除双引号? 谁能帮我 谢谢 评论 请 登录后发表观点 唱征服 2020-05-18 07:59:11 You can use the unary plus operator to transform the string numeric values to numbers: let pos = { lat: "33.5896138", lng: "73.3885526" }; let result = { lat: +pos.lat, lng: +pos.lng }; console.log(result); 希望有帮助! 点赞 评论 1起走 2020-05-18 07:59:11 use parseFloat let pos = { lat: "33.5896138", lng: "73.3885526" }; pos.lat = parseFloat(pos.lat); pos.lat = parseFloat(pos.lng) You can find more information on parseFloat() MDN 点赞 评论 ut_sed 2020-05-18 07:59:11 为了将所有对象值更改为数字,可以使用以下表达式: pos = Object.entries(pos).reduce((result, [property, value]) => ({...result, [property]: Number(value)}), {}); Now, pos is: { lat: 33.5896138, lng: 73.3885526 } 点赞 评论 到底啦
You can use the unary plus operator to transform the string numeric values to numbers:
希望有帮助!
use
parseFloat
You can find more information on parseFloat() MDN
为了将所有对象值更改为数字,可以使用以下表达式:
Now,
pos
is: