function Person (name, age) {
this.name = name;
this.age = age;
}
var family = []
var people = {alice:40, bob:42, michelle:8, timmy:6};
for (var key in people) {
family.push({key:people[key]})
}
console.log(family);
This is not giving me the keys. its giving 'key' for each key. what is the proper way to add {key:value} pair of objects in an array?
UPDATE Based on K3N solution below, this is what i understood works best if we are declaring from a constructor each time:
keys = Object.keys(people);
for (var i = 0; i < keys.length; i++) {
family.push(new Person(keys[i], people[keys[i]]));
}