This are random numbers for privacy
They should be split by the comma and put into their own constants
{
'0': '2',
'1': '5',
'2': '.',
'3': '1',
'4': '3',
'5': '4',
'6': '2',
'7': '0',
'8': '0',
'9': ',',
'10': ' ',
'11': '-',
'12': '3',
'13': '8',
'14': '.',
'15': '5',
'16': '4',
'17': '9',
'18': '2',
'19': '0',
'20': '2'
}
You can use Object.values to get an array, then join it, and split it by comma. Finally convert the split parts to number:
const data = {'0': '2','1': '5','2': '.','3': '1','4': '3','5': '4','6': '2','7': '0','8': '0','9': ',','10': ' ','11': '-','12': '3','13': '8','14': '.','15': '5','16': '4','17': '9','18': '2','19': '0','20': '2'};
const [long, lat] = Object.values(data).join("").split(",").map(Number);
console.log(long, lat);
I was going to suggest the following, but Trincot's answer is much better.
const data = {'0': '2','1': '5','2': '.','3': '1','4': '3','5': '4','6': '2','7': '0','8': '0','9': ',','10': ' ','11': '-','12': '3','13': '8','14': '.','15': '5','16': '4','17': '9','18': '2','19': '0','20': '2'};
const convertArrayItemsToInt = (digist_array) => {
return parseFloat(
digist_array.reduce((complete_number, currentDigit) => {
if (!isNaN(parseInt(currentDigit)) || currentDigit == ".") {
complete_number += currentDigit;
}
return complete_number;
}, "")
);
};
//Get only the values
const coordinates = Object.values(data);
//Get the comma index
const comma_index = coordinates.indexOf(",");
//Split the array by the comma and give it to convertArrayItemsToInt
const lat = convertArrayItemsToInt(coordinates.slice(0, comma_index));
const lng = convertArrayItemsToInt(
coordinates.slice(comma_index, coordinates.length)
);