Passing Arrays to Functions

Hi everyone!

I’m still new to Wixcode environment so be patient with me!

I’m having a problem with passing an argument of type Array to my function. All I want to do is pass my Array pizzaArray[ ] to my function printArray( ) and print out every value in the Array with a For loop. Is it possible to do this in Wixcode?

Here’s what I got:

//In my backend file
export function printArray(array)
{
let len = array.length;

console.log("Start printArray()") 

for(let i = 0; i < len; i++)
{
console.log(array[i]);
}
console.log(“Done printArray()”)
}

//In my main file
printArray(pizzaArray);

Whenever I run it, it only prints “Start printArray()” but never gets to the end. The only thing I’m guessing is that pizzaArray[ ] never reaches the inside of the function probably because I’m not passing it to the function in a correct way. Any ideas?

Thanks in advance!

Are you sure that the array isn’t empty? Do you see any errors in the log? Try console.log(len) to see if the array has any entries. Or, you can do console.log(array) to see the whole array in the console.

Hi strapizzamipizza

I don’t know if you are still having this problem but I ran into a similar problem today. I want to upload an image to Wix Media and to do that, I have to pass a very large array to the backend function to upload. I discovered that the backend function never receives the call. However, if I don’t pass the array, it gets called normally.

It seems there is a bug with Wix frontend<->backend integration where the backend function will not get called if an array of somewhere larger than 40,000 elements is passed (I sliced my array to 40,000 elements and it worked, 50,000 and it stopped working).

My solution was to convert the array to string first (using .toString()) then in the backend code, do a .split(‘,’) to convert it back into an array.

Hope this helps.