Q:

Write a JavaScript program to remove the key-value pairs corresponding to the given keys from an object

0

Write a JavaScript program to remove the key-value pairs corresponding to the given keys from an object.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const omit = (obj, arr) =>
  Object.keys(obj)
    .filter(k => !arr.includes(k))
    .reduce((acc, key) => ((acc[key] = obj[key]), acc), {});

console.log(omit({ a: 1, b: '2', c: 3 }, ['b']));
console.log(omit({ a: 1, b: 2, c: 3 }, ['c']));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now