Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda