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

139
Views
Busque en una matriz de objetos y devuelva un valor del último Objeto correspondiente en JS

Tengo dificultades para devolver un valor para el último evento que contiene "Resultados de búsqueda" en el siguiente caso: esquema de mi capa de datos donde quiero recopilar la información

Por el momento logré escribir el siguiente código para saber si existe o no un evento SearchResult:

 //Check if an existing event contains Search Results if (digitalData.event.filter(e => e.componentID === 'SearchResults').length > 0) { // If there are any that exist, I want to take the last one that was generated and return the pageIndex value of that one console.log("exist"); } else { // If it doesn't exist return 1 return 1; };

Ahora estoy luchando por encontrar una manera de seleccionar solo el último evento generado y devolver el valor contenido en "digitalData.event.attributes.pageIndex".

¿Alguien tiene alguna solución con respecto a este punto?

Gracias,

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

0

Puede guardar eso en una variable temporalmente y devolver el último resultado. ¿Es esto lo que querías?

 const searchResults = digitalData.event.filter(e => e.componentID === 'SearchResults') if (searchResults.length > 0) { const yourAnswer = searchResults[searchResults.length -1] console.log("exist"); } else { return 1; };
about 4 years ago · Juan Pablo Isaza Report

0

Filtre los artículos primero, y si hay alguno, tome el último artículo:

 const searchResults = digitalData.event.filter(e => e.componentID === 'SearchResults'); if (searchResults.length > 0) { // If there are any that exist, I want to take the last one that was generated and return the pageIndex value of that one return searchResults[searchResults.length-1].pageLength; } else { // If it doesn't exist return 1 return 1; };
about 4 years ago · Juan Pablo Isaza Report

0

Hola hermano, puedes hacer lo que quieras de esta manera.

 let getResult = digitalData.event.filter(e => e.componentID === 'SearchResults' && e.componentID.length > 0 ) if (getResult.length > 0) { const getIt = getResult[getResult.length - 1]; getResult = getIt } console.log(getResult)
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!