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
Change all blank ("") keys in object to null

Say I have an object with nested keys:

const person = {
  firstName: "John",
  lastName : "Doe",
  id       : 5566,
  nicknames: ["Johnny", "Jonathan"],
  birthDate: "", // blank string. 
};

How do I programmatically change object keys so all values that are blank ("") change to null? Like this:


const person = {
  firstName: "John",
  lastName : "Doe",
  id       : 5566,
  nicknames: ["Johnny", "Jonathan"],
  birthDate: null, // null instead of blank string. 
};

I would prefer a solution without external modules/NPM packages.

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

0

You can iterate through each property and check whether the value is a blank string, and if so, set it to null:

const person = {
  firstName: "John",
  lastName : "Doe",
  id       : 5566,
  nicknames: ["Johnny", "Jonathan"],
  birthDate: "", // blank string. 
};

Object.keys(person).forEach(e => person[e] = person[e] == "" ? null : person[e])

console.log(person)

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!