Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
how do I split and and remove white space from this latitude and longitude object?

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'
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report

0

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)
);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!