Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda