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 6846077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:34:43+00:00 2026-05-27T00:34:43+00:00

I am having a function in javascript as function add(v1,v2){ var add=v1+v2; } Now

  • 0

I am having a function in javascript as

function add(v1,v2){

var add=v1+v2;

}

Now I am calling this function as below –

write.out(var param="1,2";);

write.out(window[add](param););

Using the above call, it’s not working. What it does is it gives the complete string “1,2” as value to the first param(v1) of the function.

Its working if I call the function in following way –

write.out(var param1="1";);

write.out(var param2="2";);

write.out(window[add](param1,param2););

I want to achieve it using the first way where i can send the parameters as a comma separated string of parameters.

Can some one help me out how this can be done…

Thanks!!!

  • 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-27T00:34:43+00:00Added an answer on May 27, 2026 at 12:34 am

    You can make usage of ECMAscripts .apply(), which calls a function and accepts an array of paramters.

    window['add'].apply(null, param.split(','));
    

    That way, we execute the add function, setting its context to null (you could also change that if you need) and pass in the two paramters. Since we need an Array, we call split() on the string before.

    So basically, the above line is the same as

    add(1,2);
    

    Since you’re haveing that function in the global context (window), we don’t even need to write it that explicitly.

    add.apply(null, param.split(','));
    

    will just be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a JavaScript namespace say A={ CA: function() { this.B(); }, B:
I have the following JavaScript (I'm using jQuery): function language(language) { var text =
I'm having some IE7 (and presumably IE6) issues with the script. <script type=text/javascript> $(document).ready(function(){
Im having this function to determine weather a user exists in a database or
Having a vector containing pointers to objects then using the clear function doesn't call
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
I'm using John Resig's excellent javascript class for simple javascript inheritance and I'm having
I am new to OOP Javascript and am having trouble with the this keyword
My code is as follows: <script> $(document).ready(function() { var tagCounter=0; $(#tag-add-button).click(function () { var
I am having below html code and trying to add new values to global

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.