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

311
Vistas
How to fetch last value in the for loop using javascript?

enter image description here

    var new_data = $.parseJSON(data);
        for (var j = 0; j < new_data.all_soa_details.length; j++) {
          var td7_contact = new_data.all_soa_details[j].bal; //100,200,200,50 . here i need to fecth 50 only
          let td77_contact = Math.abs(td7_contact);
        }

i am getting values 100, 200,40,60, 50.. Here i need to fetch 50 becoz its last valuje in the for loop .How to get this last value?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

new_data.all_soa_details[new_data.all_soa_details.length - 1].bal

should give you the expected result

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this out, I just wrote a code for you..

let new_data = {
      all_soa_details: [
        {
          bal: [1, 2, 3, 45],
        },
        {
          bal: [1, 2, 3, 45],
        },
      ],
    };

    for (var j = 0; j < new_data.all_soa_details.length; j++) {
      var td7_contact = new_data.all_soa_details[j].bal; //100,200,200,50 . here i need to fecth 50 only
      let td77_contact = Math.abs(td7_contact);
    }

    // let findOut;
    // for (const lastIter of td7_contact) {
    //   findOut = lastIter; //Last iteration value stored in each iteration.
    // }
    // console.log(findOut);

    // Main code ....
    console.log(
      new_data.all_soa_details[0].bal[
        new_data.all_soa_details[0].bal.length - 1
      ]
    );

    for (let i = 0; i < new_data.all_soa_details.length; i++) {
      console.log(
        new_data.all_soa_details[i].bal[
          new_data.all_soa_details[i].bal.length - 1
        ]
      );
    }
about 4 years ago · Juan Pablo Isaza 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