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

142
Views
Grabbing certain data from one object to another object

My goal is to grab certain values from database into curated_database, however I am basically stuck at adding multiple items into an object.

var curated_database = {};

var database = {
    0: [{name: 'Micheal'}, 
        {age: 45},
        {education: 'BA'},  
        {income: 245000},  
        {occupation: 'director'}],
    1: [{name: 'John'}, 
        {age: 23},
        {education: 'BA'},  
        {income: 60000},  
        {occupation: 'manager'}],
    2: [{name: 'Judith'}, 
        {age: 45},
        {education: 'PhD'},  
        {income: 140000},  
        {occupation: 'professor'}],
    3: [{name: 'Gill'}, 
        {age: 28},
        {education: 'MS'},  
        {income: 98000},  
        {occupation: 'scientist'}],
    4: [{name: 'Dave'}, 
        {age: 17},
        {education: 'HS'},  
        {income: 30000},  
        {occupation: 'retail associate'}]
};

Goal is to grab similar certain information from the larger object


curated_database = { 
0 : ['Micheal',245000,'director'],
1: ['John',245000,'manager'],
2: ['Judith',140000,'professor'],
3: ['Gill',98000,'scientist'],
4: ['Dave',30000,'retail associate']
};

My attempt

for(data in database){
    desired_contents = [0,3,4]
    for(contents in desired_contents){
    console.log(database[data][desired_contents[contents]]);
    }
    var k = database[data][0];
    if (!currated_database[k.key]) {
        currated_database[k.key] = [];
    }
        currated_database[k.key].push(k.val);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can achieve it this way:

var curated_database = {};

var database = {
    0: [{name: 'Micheal'},
        {age: 45},
        {education: 'BA'},
        {income: 245000},
        {occupation: 'director'}],
    1: [{name: 'John'},
        {age: 23},
        {education: 'BA'},
        {income: 60000},
        {occupation: 'manager'}],
    2: [{name: 'Judith'},
        {age: 45},
        {education: 'PhD'},
        {income: 140000},
        {occupation: 'professor'}],
    3: [{name: 'Gill'},
        {age: 28},
        {education: 'MS'},
        {income: 98000},
        {occupation: 'scientist'}],
    4: [{name: 'Dave'},
        {age: 17},
        {education: 'HS'},
        {income: 30000},
        {occupation: 'retail associate'}]
};



var indexToExtract = new Set([0,3,4]);

    var wantedLst = Object.values(database)
    .map(lst => lst.filter((ob, idx) => indexToExtract.has(idx)))
    .map((lst, idx) => curated_database[idx] = lst.map(ob => Object.values(ob)[0]))
    
    console.log(curated_database);

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!