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

94
Visualizações
Loop through an array and add icon to matching given ID ONLY

I have an array of comments and I want to add an icon to only the commentID that matches the logged in user. How can I achieve this? Here is what I have. I loop through the commentList checking the commentorID and if it matches prepend the div element and if it doesn't don't show that icon. It adds the icon to all, if one elements in the array has the matching id, but I only want it to add the icon to that specific element. How can I extract it in away to still return all but only add the icon to the matching comment.

function renderCommentSection(commentList){
$('.usersComments').empty();

  commentList.forEach(function(comments, index){
   let myComments = localStorage.getItem('user');
   $('.usersComments').append(renderComments(comments));

  for(let index = 0; index < commentList.length; index++){
  if(myComments == commentList[index].commentorid){
    console.log(commentList[index].commentorid, 'Your Comment Detected')
  let editsActive = $(`
  <div class="edits">
  <button class="edit-btn"><i class="fa fa-ellipsis-v" aria-hidden="true"></i></button>
      <ul class="edit-options">
          <li>Edit<i class="fa fa-pencil-square" aria-hidden="true"></i></li>
        <li>Delete<i class="fa fa-trash" aria-hidden="true"></i></li>
    </ul>
    </div>
  
  `)
  $('.userComm').prepend(editsActive);
 }else if(myComments !== commentList[index].commentorid){
   console.log(commentList[index].commentorid, 'Not your comment');
   $('.edits').addClass('inactive')
 }
    }
    
})

};

enter image description here

about 4 years ago · Juan Pablo Isaza
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