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

176
Views
Using an Array notation for object construction in Javascript

I have the following small program to replace keys based on a condition.

Why do I need to use [] in renameKeys function to return a new object? I understand if I omit [] , it just prints

[{
  newKey: "A"
}, {
  newKey: "B"
}, {
  newKey: "C"
}]

What is the significance of array notation [] ?Is there an alternate way as I am fairly new to javascript?

const renameKeys = (obj, keyMap) => {
  const newArray = Object.keys(obj).map((key) => {
  const newKey = keyMap[key] || key;
  return {[newKey] : obj[key]};
  });
  console.log(newArray);
};

const obj = { name: "A", job: "B", school: "C" };
const result = renameKeys(obj, {
job: "NM",
name: "Name"
});
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!