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

121
Vistas
Removing an element from an array after clearing its value

I am trying to remove an element index from an array once I clear its value.

const myArray:string[] = ['123456', '234567']

const editedArray = myArray.map((m) => {
     if('123456' !== m) return m;
     return '';

const myArray = editedArray; // I want to return ['234567'] not ['', '234567]

// Type '(string | undefined)[]' is not assignable to type 'string[]'.
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

map will always return an array with the same number of elements that it's iterating over. You should use filter instead.

const myArr = ['123456', '234567'];

// `filter` accepts a string
function filter(str) {

  // Return a new filtered array that
  // doesn't contain that string
  return myArr.filter(el => {
    return el !== str;
  });

}

console.log(filter('123456'));

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think filter is the method you want.

Though not much information was provided in the question itself, map is not the right choice.

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