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

121
Views
How to filter the nested object based on the status INVALID
    var testObject = {
      address: { form: 1, status: "VALID" },
      address2: {form: 1,  status: "INVALID" },
      address3: {form: 1,  status: "INVALID" }
    }
  Object.keys(testObject)
  .filter(key => console.log(key))

What I'm trying to do here is to filter the data based on the status INVALID.

example output should be like this.

{
  address2: { form: 1, status: "INVALID" },
  address3: { form: 1, status: "INVALID" }
}

or

[
  { address2: { form: 1, status: "INVALID" } },
  { address3: { form: 1, status: "INVALID" } }
]
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

One liner:

Object.fromEntries(Object.entries(testObject).filter(x => x[1].status === "INVALID"))

Long:

const objectConvertedToArray = Object.entries(testObject)
const filteredArray = objectConvertedToArray.filter(([key, val] => val === "INVALID"))
const filteredObject = Object.fromEntries(filteredArray)
about 4 years ago · Juan Pablo Isaza Report

0

Loop over the Object.entries and add the properties that match to a new object.

var testObject = {
  address: { form: 1, status: "VALID" },
  address2: { form: 1,  status: "INVALID" },
  address3: { form: 1,  status: "INVALID" }
}

const out = {};

for (let [key, obj] of Object.entries(testObject)) {
  if (obj.status === 'INVALID') out[key] = obj;
}

console.log(out);

If you want an array push the object on to an array using the key.

var testObject = {
  address: { form: 1, status: "VALID" },
  address2: { form: 1,  status: "INVALID" },
  address3: { form: 1,  status: "INVALID" }
}

const out = [];

for (let [key, obj] of Object.entries(testObject)) {
  if (obj.status === 'INVALID') out.push({ [key]: obj });
}

console.log(out);

about 4 years ago · Juan Pablo Isaza Report

0

This should do the trick without changing the original object:

var testObject = {
  address: { form: 1, status: "VALID" },
  address2: {form: 1,  status: "INVALID" },
  address3: {form: 1,  status: "INVALID" }
}

var ouput = Object.keys(testObject).reduce((obj, element) => {
  if(testObject[element].status === 'INVALID') obj[element] = testObject[element]

  return obj
}, {})

console.log(ouput)

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!