generate an array with values of another array in javascript -
i have array values thats supposed show images randomized. want create array randomized images' name
var 1 = new array("0.jpg", "1.jpg");//first array of images for(i=0; i<=6;i++) { var random=math.floor(math.random()*(length));//randomize images of array 1 document.write('<img src="'+one[random])//display images
// after array 1 randomized want create array randomized images array 2..how can this???? going have var shuffled=new array(one[random]);
create second array doesnt work..any ideas?
you can add randomize
method array.prototype
:
array.prototype.random = function () { var result = [], = this.slice(); this.foreach(function () { result.push(that.splice(math.floor(math.random() * that.length), 1)[0]); }); return result; }
then can shuffled array with:
var shuffled = one.random();
Comments
Post a Comment