JSFiddle - React, Tailwind, and code Playground

by Vladymyr Shevchuk

JavaScript

const pick = (obj, ...fields) => {
  const arr = {};
  
  for (let arg of fields){
    if(obj.hasOwnProperty(arg))  arr[arg]=`${arg}`;
  }
  
  return arr;
};

const obj = {
  foo: 1,
  bar: 2
}

console.log(pick(obj, 'foo'));