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

278
Vistas
Get number of element in array (JS)

I have AJAX call

Here is code

 $.ajax({
        url: '@Url.Action("EmailsList", "Questions")',
        contentType: 'application/json; charset=utf-8',
        type: 'GET',
        dataType: 'json',
        processData: false,
        success: function (result) {
            var email = result;
           // console.log(result[0].Name);
            for (var i = 0; i <= email.length - 1; i++) {
                var emailHTML = '<div style="margin-left: 25px; margin-top: 10px;>' +
                    '<b style="margin-left: 10px;">' + result.indexOf(this)+
                    result[i].Email +
                    '<b>' +
                    '<b style="margin-left: 20px;">' +
                    result[i].Name +
                    '</b>' +
                    '</div>';
                $(".email_list").append(emailHTML);
            }
        }
    });
}

I need to write element number from 1, I tried this result.indexOf(this), but it not works

How I can do this?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can simply use the variable i with which you are iterating like so:

 var emailHTML = '<div style="margin-left: 25px; margin-top: 10px;>' +
                    '<b style="margin-left: 10px;">' +(i+1)+
                    result[i].Email +
                    '<b>' +
                    '<b style="margin-left: 20px;">' +
                    result[i].Name +
                    '</b>' +
                    '</div>';
                $(".email_list").append(emailHTML);

The specific reason for using (i+1) is because i starts its iteration from 0 and you want it from 1.

about 4 years ago · Santiago Trujillo Denunciar

0

If I understood, you should write something like :

var emailHTML = '<div style="margin-left: 25px; margin-top: 10px;>' +
                    '<b style="margin-left: 10px;">' + (i + 1) +
                    result[i].Email +
                    '<b>' +
                    '<b style="margin-left: 20px;">' +
                    result[i].Name +
                    '</b>' +
                    '</div>';

Just use the value of your variable i incremented in loop.

about 4 years ago · Santiago Trujillo 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