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

195
Views
¿Cómo eliminar el número (elemento) de la matriz y mostrar solo cadenas? usando vainilla js

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

estoy filtrando estos resultados y solo muestro

3, usuario, cliente, proveedores

pero solo quiero mostrar

usuario, cliente, proveedores

Quiero eliminar 3... en bucle, esta interacción de 3 en segundos será 2 o cualquier otro número...

mi intento

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

y

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

pero en ambos casos imprimo 3 ... solo quiero mostrar:

usuario, cliente, proveedores

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

0

Puede usar Array.prototype.reduce junto con una verificación si el elemento que apareció vagamente se iguala a sí mismo como un 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);

Podría lograr lo mismo con un map seguido de un filter , pero eso tendría que iterar su matriz dos veces.

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!