-1
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

Olian04
  • 6,480
  • 2
  • 27
  • 54
Atiq krl1
  • 57
  • 8
  • Isn't it just removing them and leaving without? If you want to remove special characters take a look at this question https://stackoverflow.com/questions/8979619/jquery-remove-special-characters-from-string-and-more – Eliemerson Fonseca May 18 '20 at 02:14

3 Answers3

1

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
}
Robo Robok
  • 21,132
  • 17
  • 68
  • 126
0

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

devnull
  • 1,848
  • 2
  • 15
  • 23
0

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!

Alexander Staroselsky
  • 37,209
  • 15
  • 79
  • 91