I have a JavaScript array that contains 150 JavaScript functions (these functions return financial indicators). when i load my page, i have this array. I’m wondering is it possible to use these loaded functions on that page?
I’ve converted my array to string and picture below shows how it looks like in alert mode:
arry alert mode http://bsl.site40.net/pic/8cdf49ea54ee.jpg
In above picture the (faunction a, b, c) are where my functions take place and there is 150 functions (the string {“itemCode”:___}, will be repated each time i ad a function). I think there should be some string replace and then inserting the functions on that page in someway. mmm i don’t know. can you help me?
I have another question: is it possible for a javascript array to be very long (for example 20000 characters)?
Edit: my array has complete code of functions. in that picture i showed only their name in order to picture be viewable
I would suggest you use a json object instead of an array, it will be easier to look up.
If you keep using an array you will have to loop over the array in order to find the correct functionname/function.
If your json object holds function names that are declared globally you can call them like this
But you probably should not declare your functions globally but store them in some sort of namespace.
If your json object contains the actual function ( and i would recommend this ), you can call it with
If your object contains the function code as a string, you will have to eval it to execute it. Your function will need to be wrapped in parentheses, i would not suggest this method !
You would be even better off to dynamically load the functions with some sort of jsonp.
An array can contain a maximum of 4,294,967,296 elements, but you will have obliterated your performance long before you reach that, i’m not so sure about json objects tough.