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

177
Views
¿Puedo empujar el índice en función recursiva?

mi matriz recursiva, que debería encontrar el último elemento y el índice

 let array = [1, [2, "kkkk", [9, "some", ["six", "seven", 6666, [8, "10", [10,["you find me"]]]]]]]; function findIndex(arr) { for (let [index, element] of arr.entries()){ let array = []; if(typeof element === "object"){ findIndex(element); array.push(index); console.log(array); } } } findIndex(array)

  1. agrego esta línea let array = []

  2. en la consola solo debería tener un índice como este [1,2,2,3,2], pero ahora tengo índices en diferentes matrices [1][2]...

  3. debe ser una función recursiva.

  4. ¿Puedo hacerlo con este ejemplo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let array = [1, [2, "kkkk", [9, "some", ["six", "seven", 6666, [8, "10", [10, ["you find me"]]]]]]]; const getIndexArray = (array) => { const recursiveFnc = (array, acc = []) => { // Get index of the last element in a current array const lastIndex = array.length - 1; // Get the last element in a current array const lastElement = array[lastIndex]; // Push index of last element acc.push(lastIndex); // If last element is an array go in that array recursively, if not return the last element return Array.isArray(lastElement) ? recursiveFnc(lastElement, acc) : acc; }; return recursiveFnc(array); }; const result = getIndexArray(array);
about 4 years ago · Juan Pablo Isaza 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!