mapValues
2024年06月17日
一、认识
二、语法
三、实现
function mapValues(object, iteratee) {
const objectCopy = Object(object);
const result = {};
Object.keys(objectCopy).forEach((key) => {
result[key] = iteratee(object[key], key, objectCopy);
});
return result;
}
const users = {
fred: { user: "fred", age: 40 },
pebbles: { user: "pebbles", age: 1 },
};
const result = mapValues(users, ({ age }) => age);
console.log(result);