How to pass an Array to AngularJS?

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

Was this solution helpful to you?

Just Added Q & A:

Find solution

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.