Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
How to get last item from getItems ? using javascript map

I need to get last values from items

What i try :

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

i got results:

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

WHat i need I need to get last item from link

example to get: 3, user, customer, suppliers

If you want to see all my api data is:

   {
    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 Respostas
Responde à pergunta

0

1) You can use split and map here

Thanks georg for this suggestion

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) Using regex /.*(?=\/)/

enter image description here

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) Using regex /.*(?=\/)/

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda