[Solved] How to return values from a object matched by a array?


You can access them like this, using the rest operator for arguments

var mainobject = {
  val1: 'text1',
  val2: 'text2',
  val3: 'text3',
  val4: 'text4',
  val5: 'text5'
};

function a(...args) {
var obj={};
  args.forEach((e) => {
  obj[e]=mainobject[e];
  })
  return obj;
}

console.log(a('val1', 'val4'));

3

solved How to return values from a object matched by a array?