Jeboo Scr Jeboo Scr - 4 months ago 20
Javascript Question

Javascript assign array value to text

Can anyone show me how to output array value into different place.

Eg:

var list = [1,2,3]

textbox1 = 2
textbox2 = 1
textbox3 = 3


its shuffle array

Thanks you in advance!

Answer
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;

  // While there remain elements to shuffle...
  while (currentIndex !== 0) {

    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }

  return array;
}

var list = [
        1,
        2,
        3
    ]

var shuffle_list = shuffle(list);

text1 = shuffle_list[0]; //2
text2 = shuffle_list[1]; //1
text3 = shuffle_list[2]; //3

Try this, you can shuffle array use shuffle function.

Comments