Link to home
Start Free TrialLog in
Avatar of Sri
Sri

asked on

JavaScript mapping values of one object with properties of another object like columns and rows in database

in JavaScript assign values of one object to the properties of another object

emp =  {
id :"",
name : "",
designation : ""
}

empValues = [ 
        [
           1,
            'scott',
            'manager'
         ],
         [
           2,
            'steve',
            'Director'

         ] 
,
         [
           3,
            'charlie',
            'developer'
         ]
]

Open in new window


And i i want to get the output as below after mapping properties of 'emp' object with 'empValues' object

[
  
    {
    id : 1,
    name : 'scott',
    designation : 'manager'
    },
    
    {
    id : 2,
    name : 'steve',
    designation : 'Director'

      },
      
    {
    id : 3,
    name : 'charlie',
    designation : 'developer'
      
    } 
]

Open in new window


i tried in the following way but no luck

empValues.forEach(function(value,index){
  
  empValues[index].forEach(function(value,i){
    Object.keys(emp)[i] = value ;
  });
  
});

Open in new window


is there an easier way for mapping 2 javascript objects that are in different forms?
ASKER CERTIFIED SOLUTION
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sri
Sri

ASKER

Thank you
Anytime, Glad I could.