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

137
Views
How to join the elements of an array such that the first letter is capital for all elements in JavaScript?

I want to join the elements of an array separated by commas and the first letter of each element to be capital, this should not affect the object values itself.

For example:

obj= ["apple","orange","lemon"]

Output should be: Apple, Orange, Lemon.

Here is what I have tried and failed with:

obj.charAt(0).toUpperCase().join(', ')

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

0

Here is the code:

let a = ['apple', 'orange', 'lemon'];
let res = a.map(fruit => fruit.charAt(0).toUpperCase() + fruit.slice(1));
console.log(res); // [ "Apple", "Orange", "Lemon" ]
about 4 years ago · Juan Pablo Isaza Report

0

const fruits = ["apple", "orange", "lemon"];

const new_fruits =
  fruits
    .map(x => x.replace(/^[a-z]/, (ch) => ch.toUpperCase()))
    .join(", ");

Replace first letter a-z, uppercase it and finally join with commas. Readability ftw.

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!