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

115
Visualizações
I cannot display the length of an array in ejs

So I am making a following system using mongoose.

This is the schema

const usersSchema = new mongoose.Schema({
  username: {
    type: String,
    required: true,
    unique: true,
  },
  password: {
    type: String,
    required: true, 
  },
  email: {
    type: String,
    required: true,
    unique: true,
  },
  followers:[{ type: mongoose.SchemaTypes.ObjectId,
     ref: 'User',
    default:null
  }],
  following:[{ type: mongoose.SchemaTypes.ObjectId,
     ref: 'User',
     default:null

     }]

I am trying to display the length of the length of the objects in the followers and following arrays using ejs. This is the ejs code

 <table border="1px">
                <th>
                    S. No
                </th>
            <th>Username</th>
            <th>Followers</th>
            <th>Following</th>
            <th>Edit</th>
            
        <% data.allUser.forEach((item)=> { %>
           
            <tr>
                <td>
                    <%= k++ %>
                </td>
                <td>
                    <%= item.username %>      
                </td>

                <td>
                    <% for (let l = 0; l < data.length; l++){ %>
                    <%= item.followers[l] %>
                    <%}%>
                </td>
                <td>
                    <% for (let m = 0; m < data.length; m++){ %>
                    <%= item.following[m] %>
                    <%}%>
                </td>
                <td>
                    <form action="/follow/ <%= item._id%>" method="POST" >
                        <button id="<%= item._id %>">Follow</button>
                    </form>
                </td>
                <% }) %>

The table gets rendered but the columns are empty

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