const person = {
firstName: "John",
lastName: "Doe",
age: 30,
isEmployed: true,
hobbies: ["reading", "traveling", "coding"],
address: {
street: "123 Main St",
city: "Anytown",
country: "USA",
},
greet: function () {
return `Hello, my name is ${this.firstName} ${this.lastName}.`;
},
};
const newObj = {};
for (let key in person) {
if (key === "firstName" || key === "lastName") {
newObj[key] = person[key];
}
}
console.log({ newObj });