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

246
Vistas
How can I remove ":" from the elements of array

I am Trying to convert the array [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ] to [ '900', '940', '950', '1100', '1500', '1800' ] in javascript.

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

0

You can do it in this way:-

let oldArray = ['9:00', '9:40', '9:50', '11:00', '15:00', '18:00'];
let newArray = oldArray.map(elem => elem.replace(':',''));
console.log(newArray);
about 4 years ago · Juan Pablo Isaza Denunciar

0

What you're looking for is the .map() function. This function iterates over all items in the array, allowing you to execute code on said iterations. Use what I've provided below.

const arrayOfTimestamps = [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ];

const formattedTimestamps = arrayOfTimestamps.map(time => time.replace(/:/g, ''))

As an explanation, .map() iterates over each item, and the time is being handled by regex. the /g aka global flag tells the regex to remove all semicolors's from the strings.

For more information on how .map() works, here.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

about 4 years ago · Juan Pablo Isaza Denunciar

0

Although there are other solutions that use less lines of code, the following is easier to read. Loop through your list of dates and for each date, replace the colon character with a blank.

var list = [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ];

for (var i = 0; i < list.length; i++)
{
  list[i] = list[i].replace(':', ''); 
}
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