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

119
Views
Remove/Filter object on basis of key-value combination from object

How to filter out an object from an large object on basis of certain value of one of the property.

defaultSettings = {    
'header1': {
    key: '00_02',
    element: {
        'test1': '',                        
    },
    elementName: 'footer'
},    
'enabled': {},    
'header2': [
    {
        key: '',
        value: {
            msg1: {},
            msg2: 'message2',                
        },
        elementName: 'unwanted-element1'
    }       
],
'header3': {        
    info: '',        
    headline: ''
},        
};

I want to remove the object where elementName: 'unwanted-element1' from defaultSettings

I am trying something like

for (let key of Object.keys(defaultSettings)) {                        
    if(key === 'header2'){
        if(key['elementName'] == 'unwanted-element1' ){
            //delete that particular object.
        }
    }
}
console.log(defaultSettings);

Output expected :

{    
'header1': {
    key: '00_02',
    element: {
        'test1': '',                        
    },
    elementName: 'footer'
},    
'enabled': {},    
'header2': [],
'header3': {        
    info: '',        
    headline: ''
},        
}

Kindly suggest better approach to achieve this.

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

0

defaultSettings['header2'] = defaultSettings['header2'].filter(prop => prop.elementName != 'unwanted-element1');

So here I am filtering the header2 by not including the unwanted-element1 and assigning the result to defaultSettings again.

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!