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

164
Vistas
function with array.join -help in javascript

so before anything my experience with JavaScript is not that much, I'm trying to make a function called hashtag_it with an array and i want to add # before every index in this array so when I call the function the output is going to be #programming,#code , i tried to use array.join method but it didn't really work

function hashtag_it(my_array) {
  my_array = ['programming','code']; 
  console.log(my_array.join('#'))
} 
console.log(hashtag_it());

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

0

const my_array = ['programming','code']; 
function hashtag_it() { 
   return my_array.map(item => `#${item}`).join(','); 
}
console.log(hashtag_it(my_array));

.join only joins by a separator after each element. You want to add # before each element. What I have changed is I have added map which simply appends # before each element and then you can use join(',') which joins each element using a , as a separator

References:

  • join
  • map
about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to add # to all the elements in the array and then join it. Simply using join won't add # to the first element.

function hashtag_it(my_array) {
  my_array = ['programming', 'code'];
  new_array = my_array.map(el => "#" + el).join(",")
  return new_array
}
console.log(hashtag_it());

about 4 years ago · Juan Pablo Isaza Denunciar

0

const array = ["programming", "coding", "dogs"];

const tagIt = (arr) => {
  return arr.map(word => '#'+word).join(",");
};

console.log( tagIt(array) );

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