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

231
Views
How to make unique id?

I want to make a unique id is like this :

id prefix uniqueid
1 pm pm-1
2 ad ad-1

The problem is If i want to add some data where have prefix "ad" the result must

id prefix uniqueid
1 pm pm-1
2 ad ad-1
3 ad ad-2

So the result must ad-2, ad-3 , ad-4 and go on if we add pm so the result must pm-2, pm-3 and go on

I trying to make "table helper" to me but it will be too much table

There's any idea to solve this ? I use postgres and node js ~

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

0

You could take an object with prefix as key for latest id.

const
    add = (ids => prefix => `${prefix}-${ids[prefix] = (ids[prefix] || 0) + 1}`)
          ({});
    
console.log(add('ad'));
console.log(add('ad'));
console.log(add('pm'));
console.log(add('pm'));
console.log(add('ad'));

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!