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

185
Views
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 answers
Answer question

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 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!