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

136
Vistas
convert comma separated array of element to integer value in javascript

i have got one array with string value which contain comma separator.

const array = [
  "65,755.47",
  0,
  null,
  0,
]

i want to remove the string from the value and other value remain constant in the array.

so the the output should be:--

const array = [
  65,755.47,
  0,
  null,
  0,
]

How can i achieve this?Thanks!!

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can do it with a flat map

const arr = ["65,755.47", 0, null, 0];

const res = arr.flatMap((el) => {
  if (typeof el === "string") {
    return el.split(",").map((n) => +n);
  }
  return el;
});

console.log(res);

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can do this

const data = [
  "65,755.47",
  0,
  null,
  0,
]


const result1 = data.map(v => typeof v === 'string'?v.split(',').map(Number): v)
const result2 = data.flatMap(v => typeof v === 'string'?v.split(',').map(Number): v)

console.log(result1)
console.log(result2)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Given the array

const array = ["65755.47", 0, null, 0];

You can run this

const converted = array.map((item) => item ? Number(item) : item)

Or alternatively, you have strings with comma

const array2 = ["65,755.47", 0, null, 0];

you should remove commas before converting the item

const converted2 = array2.map((item) =>
  typeof item === "string" ? parseFloat(item.replace(/,/g, "")) : item
);
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