Implement custom '.pick()' for objects
const pick = (obj = {}, keys = []) => {
const result = {};
for (const key in obj) {
if (keys.includes(key)) {
result[key] = obj[key];
}
}
return result;
};
const obj = {
name: "Mehul",
age: 27,
email: "codedrops.tech@gmail.com",
website: "codedrops.tech",
};
const keysToInclude = ["name", "age"];
console.log(pick(obj, keysToInclude)); // { name: 'Mehul', age: 27 }