It works with Array types. The example is a simple list of numbers, but the array could contain anything; lists of strings, functions, DOM nodes, whatever. Unfortunately, a lot of things that seem like arrays in the DOM aren't really, so you can't shuffle the images on a page with just document.images.shuffle() all by itself.
(function () {
var swapper =
function (a,L,e) {
var r = Math.floor(Math.random()*L);
var x = a[e];
a[e] = a[r];
a[r] = x;
};
Array.prototype.shuffle =
function () {
var i,L;
i = L = this.length;
while (i--) swapper(this,L,i);
};
})();
// example
var x = [0,1,2,3,4,5,6,7,8,9];
x.shuffle();
分享到:
相关推荐
PHP, MySQL & JavaScript All-in-One For Dummies 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
JavaScript Array对象详解_javascript技巧
PHP, MySQL, JavaScript All-in-One For Dummies 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 ...
在JavaScript中,`Array.prototype.forEach()`方法是我们遍历数组的常用方式,但不提供记住当前项的功能。而`array-iter-next-crnt`库则弥补了这一不足,它基于ES6的迭代器协议,提供了一个更灵活的迭代方式。迭代器...
根据您提供的信息,这份电子书的标题是《JavaScript高效图形编程--高清版》,描述中提到这是一本个人收集的学习用电子书,仅供学习使用,不可用于商业用途,且如果存在版权问题,应联系删除。标签为“计算机 编程”...
//get test data length 46086fetch ( 'https://raw.githubusercontent.com/internet5/smart-array-to-tree/master/example/data.json' ) . then ( function ( response ) { return response . json ( )
map = {item['key']: item['value'] for item in array} ``` 4. **C++**:C++中没有内置的映射功能,但可以使用`std::map`容器。可以迭代数组并插入键值对: ```cpp std::vector<MyStruct> array = ...; std::map,...
javascript js_leetcode题解之81-search-in-rotated-sorted-array-ii.js
javascript js_leetcode题解之154-find-minimum-in-rotated-sorted-array-ii.js
Modern JavaScript embraces a vast array of time-tested and cutting edge features. Several of these features are slowly giving shape to the next generation of web and server platforms. ES6 introduces ...
javascript array list into setjavascript array list into setjavascript array list into setjavascript array list into setjavascript array list into setjavascript array list into setjavascript array ...
In Single Page Web Applications you’ll learn to build modern browser-based apps that take advantage of stronger client platforms and more predictable bandwidth. You’ll learn the SPA design approach,...
`uglify-inplace`库的工作原理是读取指定的JavaScript文件,使用`uglifyjs`进行压缩处理,然后将处理后的结果直接覆盖原文件。这种方式避免了构建过程中需要额外的输出目录和文件复制步骤,使得整个流程更加简洁高效...
JavaScript 数组函数快速练习 想学习如何使用 JavaScript 数组函数,如 map、reduce、filter 等? 使用此工作表和相应的视频来找出方法! 样本数据 这是来自的 Star Wars 数据示例。 const characters = [ { ...
object-array-quiz-lucyk22:由GitHub Classroom创建的object-array-quiz-lucyk22
$ npm install --save lisp-array-to-js 或者,全局安装: $ npm install -g lisp-array-to-js 用法 io.js / node.js var lispArrayToJs = require ( "lisp-array-to-js" ) ; console . log ( lispArrayToJs ( ...
目前仅有的讲JavaScript的测试驱动开发的书,英文版,Amazon书评4星级的好书。
Algorithm-algorithm-implementation-in-java-javascript-scala.zip,本项目的目标是提供Java、JavaScript和斯卡拉的可重用算法集合。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
在JavaScript中,数组是常用的数据结构之一,用于存储一系列有序的元素。数组的反转操作是一项基本操作,可以方便地改变数组元素的顺序。本教程将深入探讨JavaScript中反转数组的各种实现方式及其工作原理。 首先,...