let pos = {
lat: "33.5896138",
lng: "73.3885526"
};
i have array like this but i want to remove the double quotes from latLng values? can anyone help me Thanks
let pos = {
lat: "33.5896138",
lng: "73.3885526"
};
i have array like this but i want to remove the double quotes from latLng values? can anyone help me Thanks
In order to change all the object values to numbers you can use following expression:
pos = Object.entries(pos).reduce((result, [property, value]) => (
{...result, [property]: Number(value)}
), {});
Now, pos
is:
{
lat: 33.5896138,
lng: 73.3885526
}
use parseFloat
let pos = { lat: "33.5896138", lng: "73.3885526" };
pos.lat = parseFloat(pos.lat);
pos.lng = parseFloat(pos.lng)
You can find more information on parseFloat() MDN
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);
Hopefully that helps!