2

I want a way to pass multiple arrays as function parameters (dynamically), and store their values into a single array (I know how to do this part) as demonstrated bellow:

function arrayfunction (/*arrays go here*/) {
  var allArrays = []
}
arrayfunction([a,b,c],[d,e,f],[h,i,j],...);

how can that be done?

3

2 Answers 2

2

this should get you started

function arrayfunction (/*arrays go here*/) 
{
  var outputArr = [];
  for ( var counter = 0; counter < arguments.length; counter++)
  {
    outputArr = outputArr.concat( arguments[ counter ] );
  }
  return outputArr;
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Rest Parameters if you are using babel or other transpiler which supports ES6. For ES5 you can use arguments keyword to get arguments passed to the function, but be ware that arguments is not an array, and you need to do something like var args = Array.prototype.slice.call(arguments, 1); to get an array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.