0

I have destructured my parameters in a function like so:

const obj = {a:1 , b:2, c:3, d:4}
function1(obj);

function1 ({a , b, c ,d}) {
  console.log(a);
  console.log(b);
}

now i need to pass all my params into another function. Is there a way I can acheive something like this?

const obj = {a:1 , b:2, c:3, d:4}
function1(obj);

function1 ({a , b, c ,d}) {
  console.log(a);
  console.log(b);
  func2(allMyParams) //instead of func2({a,b,c,d})    
}
Hassan Naqvi
  • 933
  • 5
  • 18
  • 2
    Consider destructuring in the function body? – evolutionxbox Nov 12 '18 at 10:23
  • please add an example of the call of function without name and `function1`. it is quite unclear if you hand over an array or a single object and what signature do you have for `function1`. – Nina Scholz Nov 12 '18 at 10:25

1 Answers1

1

you can use arguments array like object, which contains all passed parameters, since you passed 1 parameter, you can pass it to another function via arguments[0]

function asd ({a , b, c ,d}) {
  console.log(a);
  console.log(b);
  aa(arguments[0]) 
}

function aa(a) {
  console.log(a);
}

asd({a:1,b:2, c:3, d:4});
Artyom Amiryan
  • 2,846
  • 1
  • 10
  • 22