Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda