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

324
Views
¿Cómo obtener el último elemento de getItems? usando el mapa javascript

Necesito obtener los últimos valores de los artículos.

Lo que intento:

 val.links.map((link: any) => console.log('link' , link.href))

obtuve resultados:

 link https://api/v1/3 link https://api/v1/3/user link https://api/v1/3/customer link https://api/v1/3/suppliers

Lo que necesito Necesito obtener el último elemento del enlace

ejemplo para obtener: 3, usuario, cliente, proveedores

Si quieres ver todos mis datos api es:

 { id: 1, links: [ 0: {href: "https://api/3" } 1: {href: "https://api/user" } 2: {href: "https://api/customer" } 3: {href: "https://api/suppliers" } ]}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

1) Puede usar dividir y mapear aquí

Gracias Jorge por esta sugerencia.

 const result = obj.links.map((o) => o.href.split("/").pop()); 

 const obj = { id: 1, links: [ { href: "https://api/3" }, { href: "https://api/user" }, { href: "https://api/customer" }, { href: "https://api/suppliers" }, ], }; const result = obj.links.map((o) => { const matches = o.href.split("/"); return matches[matches.length - 1]; }); console.log(result);

2) Usando expresiones regulares /.*(?=\/)/

ingrese la descripción de la imagen aquí

 const obj = { id: 1, links: [ { href: "https://api/3" }, { href: "https://api/user" }, { href: "https://api/customer" }, { href: "https://api/suppliers" }, ], }; const result = obj.links.map((o) => o.href.replace(/.*(?=\/)/, "").slice(1)); console.log(result);

3) Usando expresiones regulares /.*(?=\/)/

 const obj = { id: 1, links: [ { href: "https://api/3" }, { href: "https://api/user" }, { href: "https://api/customer" }, { href: "https://api/suppliers" }, ], }; const result = obj.links.map((o) => o.href.match(/.*\/(.*)/)[1]); console.log(result);

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!