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

85
Visualizações
The dom list renders unwanted comma or quotations marks

for my current code renders coma, quotation marks between my list items, not sure what the issue please help.

I change the code to this for it to be easier to read: "null" in tinary operator works and changing it doesn't affect the problem or result. (currentCollection[indexOf item].Words are an array of words and regex = /[a-z]/g)

 for (let i = 0; i < currentCollection.length; i++) {
    let words = currentCollection[i].Words.join(" ")
    elementsString += `<div><h2>${currentCollection[i].name}</h2>
     <ul>
     
     ${currentCollection[i].Words.map(word => regex.test(word) ? (`<li>${word}</li>`) : null

    )}</ul></div>`
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like you're trying to do something like this. I'm not sure what that test is meant to do so I left it out. But I added some CSS to make it look pretty.

const arr = [
  { id: 1, name: 'Alpaca', words:['a', 'b'] },
  { id: 2, name: 'Moose', words:['c', 'd'] },
  { id: 3, name: 'Tiger', words:['e', 'f'] },
  { id: 4, name: 'Sparrow', words:['g', 'h'] }
];

// `map` over the array of words to create a
// list of items
function getItems(words) {
 return words.map(word => {
    return `<li>${word}</li>`;
  }).join('');
}

// `map` over the array to create a heading
// and a list of items in an unordered list element
const html = arr.map(obj => {
  const { name, words } = obj;
  return `
    <div>
      <h2>${name}<h2>
      <ul>${getItems(words)}</ul>
    </div>
  `;
}).join('');

document.body.innerHTML = html;
h2 { font-size: 1em; }
ul { font-weight: 400; list-style: none; margin-left: 0; padding-left: 0; }
li { padding: 0.2em; margin-left: 0.5em; text-transform: uppercase; }
li:hover { cursor: pointer; background-color: #ffff00; }

Additional documentation

  • Destructuring assignment
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