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

217
Views
Explain the use of brackets in a replace function return?

I have a replace function that works like this:

let componentJSON = [
  { "template": "<div class='${layout} ${border}'></div>" },
  {
    "layout": "grid",
    "border": "primary"
  }
];

const template = componentJSON[0].template
const classes = componentJSON[1]

let html = template.replace(/\$\{(.*?)\}/g, (match, key) => classes[key]);

console.log(html);

There's one part of this that I don't understand, and that's the classes[key] at the end of the arrow function - is this something specific to replace? I think I've seen it in map methods too.

Would be interested to see if there's a name for this or another clearer way of writing it?

about 4 years ago · Juan Pablo Isaza
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!