0

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));
}
}

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I should have thought of that... would you suggest any solution to it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.