Javascript examples for Array Operation:Array Element
generate an array with values of another array in javascript
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from ww w .j ava2 s. c om*/ arr = [1,2,3,4,5,6,7,8]; Array.prototype.random = function () { var result = [], that = this.slice(); this.forEach(function () { result.push(that.splice(Math.floor(Math.random() * that.length), 1)[0]); }); return result; } document.body.innerHTML = arr.random(); } </script> </head> <body> </body> </html>