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

136
Views
Remove the extra space in object value

I'm trying to remove the extra space inside of the object value.

const object = {
    primaryInformation: {
       firstName: "John  Doe",
       lastName: "Doe     Space"
    }
}

Is there any simplest way to remove the extra space between the words of object value using map?

Expected Output

firstName: "John Doe",
lastName: "Doe Space" 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Based on the object structure in your question, I've written this loop.

const object = {
  primaryInformation: {
    firstName: "John  Doe",
    lastName: "Doe     Space"
  }
};

for (const key in object) {
  const value = object[key];

  for (const key2 in value) {
    const string = value[key2];

    value[key2] = string.replace(/  +/g, " ");
  }
}

console.log(object);

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!