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

307
Vistas
remove space, -, () from phone number

I have an array of objects which are phone numbers such as:

phoneArray = [{"phone": "+11 111 111"},{"phone": "+22 222 222"}]

I did a loop on it to remove spaces because I want this result:

[{"phone": "+11111111"},{"phone": "+22222222"}]

but I only could remove the first space which looked like

[{"phone": "+11111 111"},{"phone": "+22222 222"}

with this code:

for(i=0 ; i<phoneArray.length ; i++) {

let test = phoneArray[i].phone.replace(" ","");
}

I actually have other phone numbers like {"phone": "(22) 222-222"} to format but if I can remove space I can remove other signes like ()- I think.

I don't use regex because I don't understand it yet.

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

0

To remove all characters except for + and numbers, you can do this:

let p = "+1 (555) 555-555"

console.log(p.replace(/[^\d\+]/g,''))

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can pass a regex pattern to your replace function. Like that:

let p = "+(11) 111 111-11"

console.log(p.replace(/[\s\-\(\)]/g,''))

about 4 years ago · Juan Pablo Isaza Denunciar

0

I would use the map function to iterate the array and change each of the values, to each value will apply the function replace with a regex in order to remove the non digits number and +.

phoneArray = [{"phone": "+11 111 111"},{"phone": "+22 222 222"}]
phoneArray = phoneArray.map(p => {
   return {
     phone: p.phone.replace(/[^+\d+]/g,"")
   }
})
console.log(phoneArray)

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