How to pass Array to function with single number (instead of accidental creating an empty array of that length?
-
In my HTML I have a JavaScript function call as such: fnShowHide(this, Array(1,3,8),'tag','summary'); The numbers in the array are generated dynamically. There is a case where sometimes the Array will appear as such: fnShowHide(this, Array(4),'tag','summary'); The problem is this breaks the function because instead of receiving an array with the number 4 it receives a blank array with length of 4. How do I pass the number 4 into the function like this. Note: the function will iterate through the for loop so the passed value has to be compatible with this. Thanks for your help and let me know if I need to provide more information.
-
Answer:
Are you able to use literal array syntax? Eg: fnShowHid(this, [4]...); In fact, the second link advises against using the Array(...) constructors.
bar338 at Yahoo! Answers Visit the source
Related Q & A:
- How to pass multiple parameters in a single Ajax function?Best solution by stackoverflow.com
- How to pass javascript jQuery variable value in php array?Best solution by Stack Overflow
- How to change array elements?Best solution by Stack Overflow
- How to access a nested function from another nested function in javascript?Best solution by devarticles.com
- How to pass a parameter to a function that is called on an event?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.