The difference between slice() and splice()
来源:互联网 发布:centos 7 dhcp ip配置 编辑:程序博客网 时间:2024/06/01 09:14
1、slice(start,stop):get specific elements from an array and has no impact on the array. stop is not necessary.
If exists,the function will extract string from start to stop(not included).
If not,from start to end.
<script> var arr=[1,2,3,4,5]; console.log(arr.slice(1)); //2,3,4,5 console.log(arr.slice(1,3)); //2,3 console.log(arr); //1,2,3,4,5</script>
2、splice(index,howmany,item1,…..,itemX):return elements that are deleted.
index is where to add or delete elements.
howmany is howmany elements will be deleted.
item 1…intemX (not necessary)are elements that will be added to the array.It will change the original array.
<script> var arr=[1,2,3,4,5]; console.log(arr.splice(1,2)); //2,3 (arr:[1,4,5]) console.log(arr.splice(1,1,6)); //4 (arr:[1,6,5]) console.log(arr); //1,6,5</script>
▲:think about :substr() and substring()
0 0
- The difference between slice() and splice()
- The difference between (()) and ().
- the difference between "./" and "sh"
- the difference between the SOURCELIBS and TARGETLIBS
- The difference between Const and ReadOnly
- The difference between Failure and Success
- The difference between Process and Procedure
- The difference between GetDC and GetWindowDC
- The difference between Chinese and American
- The difference between J2ee and Ruby
- The difference between SendMessage and PostMessage
- The difference between lint and gcc
- The difference between sizeof and strlen
- The Difference Between Internet, Intranet, and Extranet
- The difference between CLOCK_MONOTONIC and CLOCK_REALTIME
- The difference between UTF8 and AL32UTF8
- Learn the difference between SCSI and IDE
- the difference between substr and substrb
- Android 6.0权限注意点
- react native输入框 输入金额等数据后如何格式化显示
- lightoj 1076 【二分找满足条件的最左】
- JS打乱数组顺序
- Network In Network
- The difference between slice() and splice()
- 获取浏览器的高度
- android自定义View
- java mysql的latin1转UTF-8
- Activity、Fragment转场动画
- CSS设置文字不换行,超出部分用 ... 代替
- php正则判断一个变量是否为正整数
- Web学习笔记(持续更新中……)
- 硬件工程师电路设计必须紧记的十大要点