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

181
Views
Can i use internationalisation api to format sentence to have "and" word before last item?

I am trying to create a string with where i want to have the following

  1. there should be and word before the last word in the sentence
  2. if there is just one word then no and.

for and array ['john','harry', 'darren']

i expect below

e.g john harry and daren

is it even a valid case for internationalisation or am i better off just programming do this?

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

0

You may create a function, and the body will look something like this:


function myFunc (a) {
    if (a.length > 1) {
        const exceptLast = a.slice(0, -1)
        let last = a.slice(-1)
        last = ['and', ...last]
        return [...exceptLast, ...last].join(" ")
    }
    return a[0]
}

Test it like this:


const da = ['b', 'cc', 'ddd']
const da1 = ['b']
const da2 = ['b']



console.log(myFunc(da))
console.log(myFunc(da1))
console.log(myFunc(da2))
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!