0

The way I want to destruct my object is a bit different from common ways. I did search a lot and since I did not know the exact term for what I wanted so I could not find any solutions.

for simplicity, let's assume I have an object in react-native and my object has the following structure

const myObject = {
  name: 'someOne',
  lastname: 'anyThing',
  social: 'a very social guy',
  sports: 'gym, ufc',
}

the last two params (key social, sports and values a very social guy, gym, ufc) can be anything.

I have a function called destructure

const destructure = (myObject, firstHobby, secondHobby) => {
  const { name, lastname, firstHobby, secondHobby } = myObject;

  // 
  // My codes
  //
}

I am calling the destructure function in my code somewhere like

destructure(myObject, 'socail', 'sports');

and I want to be able to call it on some other object as

destructure(myObject, 'network', 'studies')

My function should be able to destructure both objects. Is it possible? Thanks in advance

0 Answers0