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

145
Views
How do I capitalize every letter that has a period immediately after it in Javascript in a concise manner?

I have the following string A.b.c. This is an example

I would like to make it so that any letters which have a period immediately after them are capital.

This is the code I currently have, which works. Any ideas on how to make this more concise?

let testString = 'A.b.c. This is an example'
const pieces = testString.split('.')

let tempString = ''
let replaceString = ''
pieces.forEach(piece => {
  if (piece.length === 1) {
    tempString += piece.toUpperCase() + '.'
    replaceString += piece + '.'
  }
})

let newString = testString.replace(replaceString, tempString)
console.log(newString)

//A.B.C. This is an example

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This can be done with a regular expression and a custom replacement function. It may look cleaner if you're not bothered by the ugliness of regular expressions.

let testString = 'A.b.c. This is an example.';
let newString = testString.replace(/\w\./g, letter => letter.toUpperCase());
console.log(newString);

about 4 years ago · Santiago Trujillo 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!