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

186
Visualizações
How to remove number ( item ) from array and show only strings? using vanilla js

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

i am filtering this results and show only

3, user, customer, suppliers

but i want to show only

user, customer, suppliers

I want to remove 3... in loop this 3 in seconds interation will be 2 or any other number..

My try

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

and

const result = obj.links.map((o) => o.href.replace(/.*(?=\/)/, "").slice(1));

but in both case i print 3 ... i want to show only :

user, customer, suppliers

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use Array.prototype.reduce along with a check if the element popped loosely equals itself cast to a Number.

const links = [{"href": "https://api/v1/3"},{"href": "https://api/v1/3/user"},{"href": "https://api/v1/3/customer"},{  "href": "https://api/v1/3/suppliers"}];

const result = links.reduce((acc, {href: link}) => {
  const last = link.split('/').pop();
  if (!(last == Number(last))) acc.push(last);
  return acc;
}, []);

console.log(result);

You could achieve the same with a map followed by a filter, but that would have to iterate your array twice.

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