0

I have a function which just return the part of existing object. in this case I am using Object destructuring but for this I need to repeat my code twice, one for retrieving properties and once for creating object like below.

function getPartlyState(obj) {
  const { x, y, z } = obj;
  return { x, y, z };
  //**OR**
  return { x: obj.x, y: obj.y, z: obj.z };
} 

Is there any better way where I dont have to repeat my properties, something like below.

function getPartlyState(obj) {
  return { x, y,z } = obj;
} 
Atul
  • 3,013
  • 2
  • 12
  • 15

0 Answers0