0

I managed to pull a string element from My_array then remove it temporarily till the next browser refresh but how to remove it completely so that element is completely gone?

<script>
Array.prototype.randsplice = function() {
    var ri = Math.floor(Math.random() * this.length);
    var rs = this.splice(ri, 1);
    return rs;
};

var my_array = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
var result = my_array.randsplice();

document.write(result);
document.write("<hr>");
document.write(my_array);

Yari
  • 15
  • 5
  • 3
    Uhhh... reloading the page wipes anything you've done in the current one. You'll need to use storage, eg. `localStorage`. – Niet the Dark Absol Aug 09 '17 at 15:21
  • 1
    On every browser refresh, you will get same set of array, unless you use some kind storage like cookies or server side storage – pravid Aug 09 '17 at 15:22
  • 1
    You can use cookies as local storage and on every browser refresh fetch data from this cookie. Also note that, this data is stored till the browser history/cookies is not cleared. Checkout https://github.com/js-cookie/js-cookie – pravid Aug 09 '17 at 15:28
  • Right, of course! so simple.... Thanks, – Yari Aug 09 '17 at 15:29
  • Exactly was was I was looking for. Thanks trupti. – Yari Aug 09 '17 at 15:37

0 Answers0