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

101
Views
how to remove {} empty field in array .. nodejs

i am using below code...but if Status is Empty iss show below result in database...i want to remove if Status is Empty ..

1 Address {}, Status {} save in database.

function CheckStatus(oldJob, newJob) {
  var obj = {};
  if(newJob && newJob.Status) { 
   obj.Status= {}; 
    if (oldJob.Status.total !== newJob.Status.total) {
      obj.Status.total = newJob.Status.total;
    }
    if (oldJob.Status.charge_description && oldJob.Status.charge_description !== newJob.Status.charge_description) {
      obj.Status.charge_description = newJob.Status.charge_description;
    }
  }
}

Mongodb

 "Job" : {
        "_id" : ObjectId("5873b352e7621d08fccc5890"),
        "updated_by" : "",
        "details" : "{\"current_status\":\"Completed\",\"address\":{},\"Status\":{}}",
        "changetype" : "Update",
        "datetime" : ISODate("2017-01-09T15:59:14.202Z")
    },

please help how what enter in If Condition ( below code not working)

 if(obj.address = '{}')
  {
   console.log('Empty');

  }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Setting an object's value to undefined essentially removes them. You can easily use the undefined keyword like so:
newJob.address = undefined;

How would you search for an empty object and remove its content:

 if(Object.keys(newJob.address).length === 0) { newJob.address = undefined; }

The solution is better explained in the answers to this question:
How do I test an empty JavaScript object?

over 4 years ago · Santiago Trujillo 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!