如何最简洁地检查一个对象是否包含数组中指定的所有键?
例如:
var arr = ["foo", "bar"];
var obj = {
foo: 1,
bar: "hello"
};
magic_function(arr, obj); // return true, all keys from array exist
var obj2 = {
foo: 12,
bar: "hi",
test: "hey"
};
magic_function(arr, obj2); // return true, all keys from array exist,
// keys not specified in array don't matter
var obj3 = {
foo: 5
};
magic_function(arr, obj3); // return false, "bar" is missing
magic_function
在哪里? - Satpal