mercredi 5 août 2015

How to remove element from array in Javascript?

So I'm trying to randomly select an element from a string, copy that element into another array, and then delete the randomly selected element from the original string. However, I can't seem to get my code to do this properly. I tried slicing and popping the original string but neither technique seems to work, and I don't know why. If anyone could help, I would be very appreciative.

    for (var i=0; i < inputword.length; i++)
    {
      letter = inputword[Math.floor(Math.random() * inputword.length)];
      anagram[i]=letter;
      inputword.slice(letter,1);
    }
    $("label").text(anagram);




Aucun commentaire:

Enregistrer un commentaire