javascript - Remove the previous value and update the array -
having problem removing previous value array , updating remaining data.
for example, in code jsfiddle have 4 values in array: bmw, nissan, volvo , saab.
var cars = ["saab", "volvo", "bmw" , "nissan"]; shuffle(cars); document.getelementbyid("demo").innerhtml = cars[0];
so, once "press button" shows "bmw" or other value, next time reloading should randomize within rest of value i.e. nissan, volvo , saab.
var cars = ["saab", "volvo", **"bmw"** , "nissan"];
until ends , shows "no more value shown"
function shuffle(array) { return array.splice(math.random() * array.length, 1).pop(); } var cars = ["saab", "volvo", "bmw" , "nissan"]; var car = shuffle(cars); document.getelementbyid("demo").innerhtml = car;
update
also note jsfiddle reloading whole js each time, ie. reloading initialization of cars
each time, it's refreshing 4 initial values each time run it.
Comments
Post a Comment