Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5955171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:04:33+00:00 2026-05-22T18:04:33+00:00

Possible Duplicate: How to create a function and pass in variable length argument list?

  • 0

Possible Duplicate:
How to create a function and pass in variable length argument list?

I want to call the console.log with variable argument list

console.log("a","b")
console.log("a","b","c")

but i get the arguments from an array:

var arr = ["a","b","c"];

and i want to pass as single variables not as a complete array.
so console.log(arr) is not what i am looking for,console.log(arr[0],arr[1],arr[2]) is also bad because i dont know the array length ofc.

How can i do that?

the console.log is only an example, i would use this in different problems


UPDATE

How to create a function and pass in variable length argument list? is not good. because according to the answer

function dump(a,b) {
  console.log("a:"+a,"b:"+b);
}

var asd = [1,2,3]

dump.call(this,asd)

should give an output: a:1,b:2 instead of a:[1,2,3] b:undefined


UPDATE:

maybe my question was not clear enough, sorry.

The console.log is only a example of variable argument invoking

i want to use the same method for different problems

look at this example:

function Sum() {
  var temp = 0;
  for(var i=0;i<arguments.length;++i) {
     temp+= arguments[i];
  }
  return temp;
}

and i want to call with different arguments which are in an array.

var test1 = [1,2,3];
var test2 = [4,5,6];

var a = Sum.call(this,test1) //this gives an output "01,2,3"

var b;
for(var i=0;i<test2.length;++i) {
  b = Sum(test2[i])
} //this is also bad because it only returns 6 at the last invoke.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:04:34+00:00Added an answer on May 22, 2026 at 6:04 pm

    Use Function.apply:

    console.log.apply(console, arr);
    

    This answers the question you asked. If you intended to ask:

    Why does dump.call(this,asd) result in an output of “a:[1,2,3] b:undefined”?

    The answer (which any documentation will tell you) is that Function.call is variadic, and any arguments after the first are passed to the function, whereas Function.apply takes only two arguments: a value for this in the applied function and an array of arguments to pass to the function.

    In other words, Function.call is equivalent to:

    function (self) {
        var args = [].slice.apply(arguments, [1]);
        return this.apply(self, args)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know its probably possible, but is it practical and doable to try and
I know its probably possible, but is it practical and doable to try and
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I am trying to load a html page through UIWebview.I need to disable all
I'm trying to write test harness for part of my Android mapping application. I
I am writing a query to fetch results for all the values in a
I'm trying to build a Chrome browser extension, that should enhance the way the
My question is about memory use and objects in actionscript 2. If I have
This is beyond both making sense and my control. That being said here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.