Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

552
Views
Eliminar elemento [i] de jQuery cada bucle

¿Cómo elimino un artículo[i] de los artículos una vez que llega a:

 $.each(items, function(i) { // how to remove this from items });
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Sería mejor no usar $.each en este caso. Use $.grep en su lugar. Esto recorre una matriz prácticamente de la misma manera que $.each con una excepción. Si devuelve true desde la devolución de llamada, el elemento se conserva. De lo contrario, se elimina de la matriz.

Su código debería ser algo como esto:

 items = $.grep(items, function (el, i) { if (i === 5) { // or whatever return false; } // do your normal code on el return true; // keep the element in the array });

Una nota más: this en el contexto de una devolución de llamada $.grep se establece en window , no en el elemento de matriz.

over 4 years ago · Santiago Trujillo Report

0

Supongo que quieres $.map . Puede return null para eliminar un elemento y no preocuparse por cómo pueden cambiar los índices:

 items = $.map(items, function (item, index) { if (index < 10) return null; // Removes the first 10 elements; return item; });
over 4 years ago · Santiago Trujillo Report

0

Si desea eliminar un elemento de la matriz, use splice()

 var myArray =['a','b','c','d']; var indexToRemove = 1; // first argument below is the index to remove at, //second argument is num of elements to remove myArray.splice(indexToRemove , 1);

myArray ahora contendrá ['a','c','d']

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!