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

102
Views
How to format filtered strings and return formated values? Vanilla JS loop

I have array:

   link https://api/v1/3
   link https://api/v1/3/user-data
   link https://api/v1/3/customer-data
   link https://api/v1/3/suppliers-sup

i am filter array :

 let res = val.match(/.*\/(.*)/)[1];

second way to filter :

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

And right now results is:

[
  "user-data",
  "customer-data",
  "suppliers-sup"
]

first logic way is with "3" item but no important for now.

What i need ? to filter to results be:

[
  "User data",
  "Customer data",
  "Suppliers sup"
]

With first letter big and to remove "-" and apply space

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

0

In a concise manner, you can achieve your result as -

console.log(
  [
    "https://api/v1/3",
    "https://api/v1/3/user-data",
    "https://api/v1/3/customer-data",
    "https://api/v1/3/suppliers-sup"
  ].reduce((acc, href) => {
    let result = href.replace(/.*\/([a-z])?(.*)/,
      (_, $1, $2) => $1 ? $1.toUpperCase() + $2 : "")

    if (result) return [...acc, result]
    return acc
  }, [])
)

about 4 years ago · Juan Pablo Isaza Report

0

You can format the data like this:

// Sample Data
const data = [
  "user-data",
  "customer-data",
  "suppliers-sup"
]

const formattedData = data.map(item => {
  // Seperate words into an array
  let dataItems = item.split("-")

  // Capitalize first letter of each word
  dataItems = dataItems.map(word => word.charAt(0).toUpperCase() + word.slice(1))

  // Join the words back together
  return dataItems.join(" ")
})
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!