Reputation: 4632
I don't quite understand what's wrong with my function that I wrote,
When I pass an array to it, eg:
var pvars=['health/1/1.jpg','health/1/2.jpg','health/1/3.jpg','health/1/4.jpg'];
cache_threads(pvars,1);
Then I end up with an empty variable, eg:
alert(pvars);
Returns an empty string.
Here is my function:
var cache_threads=function (arruy,quant){
if (quant==undefined) quant=1;
var div=Math.ceil(arruy.length/quant);
var a = arruy;
while(a.length) {
cache_bunch(a.splice(0,div));
}
}
Upvotes: 0
Views: 60
Reputation: 339786
a
and arruy
are the same array.
When you .splice
one, you'll be splicing the other one, too!
If you want a (shallow) copy of the array, use .slice()
:
var a = arruy.slice(0);
Upvotes: 1