Q:

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

0

Write a JavaScript program to pick 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 pick = (obj, arr) =>
  arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
console.log(pick({ a: 1, b: '2', c: 3 }, ['a', '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