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
How to empty the strings in an array of strings, but keep the length of array

I have an array of strings in javaScript:

array = ['xx', 'xxxxxxxx', 'xxx'];

I want to reach this:

 array = ['', '', '']; //empty the strings but keep the length of array

What is the best way?

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

0

Use Array.fill.

array = ['xx', 'xxxxxxxx', 'xxx'];
array.fill('');
console.log(array)

If you need to create a new array, use the Array constructor combined with Array.fill:

array = ['xx', 'xxxxxxxx', 'xxx'];
const newArray = new Array(array.length);
newArray.fill('');
console.log(newArray)

about 4 years ago · Juan Pablo Isaza Denunciar

0

use .map method to remove content and return the empty string.

array = ['xx', 'xxxxxxxx', 'xxx'];
const newArray = array.map(data=> (""));
console.log(newArray)

about 4 years ago · Juan Pablo Isaza Denunciar

0

array = array.map(function(item){return '';});
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