我一直在努力创建一个带有 source 和 keys 参数的 omit 函数,它检查源中的键,如果找到它们,则从源中省略这些属性,然后使用剩余的键创建一个新的对象文字/源中的值对。到目前为止,我一直没有成功,并且只能创建一个与使用源中找到的键创建对象相反的函数。谁能帮我弄清楚我错过了什么?将不胜感激!
function omit(source, keys) {
var includedSource = {};
for (var key in source) {
for (var i = 0; i < keys.length; i++) {
if (keys[i] !== key) {
includedSource[key] = source[key];
console.log('source[keys[i]]:', source[keys[i]]);
console.log('includedSource:', includedSource);
}
}
}
return includedSource;
}
function omit(source, keys) {
var includedSource = {};
for (var key in source) {
for (var i = 0; i < keys.length; i++) {
if (keys[i] === key) {
includedSource[key] = source[key];
console.log('source[keys[i]]:', source[keys[i]]);
console.log('includedSource:', includedSource);
}
}
}
return includedSource;
}