Created
May 16, 2013 02:06
-
-
Save RockyMyx/5588907 to your computer and use it in GitHub Desktop.
JavaScript: Array-memo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [1, 2, 3, 4, 5]; | |
//从第二个下标,删除0个元素,并插入一个6,无返回值 | |
arr.splice(2, 0, 6); | |
//从第二个下标,删除1个元素(3),并插入一个'6'--等同于替换index=3的元素,返回被删除的元素集合([3]),arr->[1, 2, 6, 4, 5] | |
arr.splice(2, 1, 6); | |
//从第二个下标,删除2个元素(3,4),并插入一个6,返回被删除的元素集合([3,4]),arr->[1, 2, 6, 5] | |
arr.splice(2, 2, 6); | |
//从第二个下标,删除1个元素(3),并插入一个6,7,8,返回被删除的元素集合([3]),arr->[1, 2, 6, 7, 8, 4, 5] | |
arr.splice(2, 1, 6, 7, 8); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment