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

400
Views
Eliminar el primer elemento de la matriz (como sacar de la pila)

Tengo una lista de elementos creados a través ng-repeat . También tengo el botón Eliminar. Al hacer clic en el botón Eliminar, se elimina el último elemento de la matriz uno por uno. Plunker

Pero quiero eliminar elementos uno por uno a partir del primer elemento. ¿Cómo puedo hacer eso? Usé esto para eliminar elementos de la lista:

 $scope.index = 1; $scope.remove = function(item) { var index = $scope.cards.indexOf(item); $scope.cards.splice(index, 1); }

¿Hay alguna manera de que pueda quitar de la parte superior?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

La forma más fácil es usar shift() . Si tiene una matriz, la función de shift desplaza todo a la izquierda.

 var arr = [1, 2, 3, 4]; var theRemovedElement = arr.shift(); // theRemovedElement == 1 console.log(arr); // [2, 3, 4]
over 4 years ago · Santiago Trujillo Report

0

Simplemente use arr.slice(startingIndex, endingIndex) .

Si no especifica el endingIndex , devuelve todos los elementos a partir del índice proporcionado.

En su caso arr=arr.slice(1) .

over 4 years ago · Santiago Trujillo Report

0

const a = [1, 2, 3]; // -> [2, 3] // Mutable solutions: update array 'a', 'c' will contain the removed item const c = a.shift(); // prefered mutable way const [c] = a.splice(0, 1); // Immutable solutions: create new array 'b' and leave array 'a' untouched const b = a.slice(1); // prefered immutable way const b = a.filter((_, i) => i > 0); const [c, ...b] = a; // c: the removed item
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!