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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:43:55+00:00 2026-06-04T01:43:55+00:00

I have an array with random count of elements, for example: var array =

  • 0

I have an array with random count of elements, for example:

var array = [1, 2];

And I want to execute some function with the next parameters:

functionName(SOME_CONST, array[0], array[1])

What is the best way to do this, considering that array could have a different number of parameters?

  • 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-06-04T01:43:57+00:00Added an answer on June 4, 2026 at 1:43 am

    Have a look at https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply for details on how to use the Function.prototype.apply method.

    So long as you want to use all of the items in your array as arguments in the function that you are calling, you can use:

    function some_method(a, b, c) {}
    
    var array = [1,2];
    some_method.apply(this, ['SOME_CONST'].concat(array));
    

    which will result in calling some_method with a being the ‘SOME_CONST’ and b and c being the first two elements in the array. If you had more elements in the array, they would come next in the arguments list in the some_method function.

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

Sidebar

Related Questions

So, I have a string array of some random saying and the like, but
I have a 1D array that got i*50 elements..i is a random number and
I have a 1-dimensional array that fills up a table of 40 random elements
Say I have a 2D array of random boolean ones and zeroes called 'lattice',
I have an array of strings of random letters, and I need to know
I have a code segment that generates a dynamic 3D array of random numbers
Possible Duplicate: Non repeating random number array I have a String array with many
Background: I have an N-length array of positive random numbers that are certain to
I got requirements- 1. Have random values in a List/Array and I need to
I have in C++ an array of 100 elements, so v[1], ... ,v[100] contains

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.