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

154
Vistas
Javascript, removing a row within an object

Best way to remove a row off an object based off a certain condition?

Down below I made a function to remove any row where the difference of the amount within latest row and any other row is greater than 300.

bank_data = [{"arrival_time":"12:00","amount":"900","id":"BS"},  
{"arrival_time" :"12:00","amount":"300","id":"BD"},
{"arrival_time" :"01:00","amount":"400","id":"SW"},
{"arrival_time" :"03:00","amount":"800","id":"OS"},
{"arrival_time" :"03:00","amount":"500","id":"SF"},
{"arrival_time" :"04:00","amount":"600","id":"SJ"},
{"arrival_time" :"04:00","amount":"600","id":"FS"},
{"arrival_time" :"06:00","amount":"900","id":"JC"}];

function update_list(obj){
    if(obj.length > 0) {
        latest = obj.length -1; 
        for(var i = 0; i < obj.length; i++){
            if((obj[latest].amount - obj[i].amount) > 300){
                obj.splice(i, 1);//remove the ith row of the object
            }
        }
    }
    return obj;
}


Goal Result

bank_data = [{"arrival_time":"12:00","amount":"900","id":"BA"},  
{"arrival_time" :"03:00","amount":"800","id":"OS"},
{"arrival_time" :"04:00","amount":"600","id":"SJ"},
{"arrival_time" :"04:00","amount":"600","id":"FS"},
{"arrival_time" :"06:00","amount":"900","id":"JC"}];
about 4 years ago · Juan Pablo Isaza
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