js-语法
js中slice方法(转)
1、String.slice(start,end)
returns a string containing a slice, or substring, of string. It does not modify string。
slice()返回一个子片段,对原先的string没有影响,与subString的区别是,还可以用负数当参数,相当于是length+start,length+end.
Example:

var s = "abcdefg";
s.slice(0,4) // Returns "abcd"
s.slice(2,4) // Returns "cd"
s.slice(4) // Returns "efg"
s.slice(3,-1) // Returns "def"
s.slice(3,-2) // Returns "de"
s.slice(-3,-1) // Should return "ef"; returns "abcdef" in IE 4

2.Array.slice(start,end)
returns a slice, or subarray, of array. The returned array contains the element specified by start and all subsequent elements up to, but not including, the element specified by end. If end is not specified, the returned array contains all elements from the start to the end of array.
返回从start开始到end的子数组,如果end这个参数没有被设置,则返回从start开始到最后的数组元素。
Example:
var a = [1,2,3,4,5];
a.slice(0,3); // Returns [1,2,3]
a.slice(3); // Returns [4,5]
a.slice(1,-1); // Returns [2,3,4]
a.slice(-3,-2); // Returns [3]; buggy in IE 4: returns [1,2,3]
除了正常用法,slice 经常用来将 array-like 对象转换为 true array。在一些框架中会经常有这种用法。
Array.prototype.slice.call(arguments);//将参数转换成真正的数组.
因为arguments不是真正的Array,虽然arguments有length属性,但是没有slice方法,所以呢,Array.prototype.slice()执行的时候,Array.prototype已经被call改成arguments了,因为满足slice执行的条件(有length属性).
js-语法的更多相关文章
- JS语法(二)
JS变量 var 变量名 = 变量值://自己会判断什么类型 一个好的编程习惯是,在代码开始处,统一对需要的变量进行声明. var name = “xiaosan”, age = 22, addres ...
- Sublime text3 JS语法检测工具安装及使用
Sublime text3 JS语法检测工具安装及使用 工具/原料 sublime text3 nodejs sublimeLinter sublimeLinter-jshint 方法/步骤 首先ct ...
- python+selenium十一:jQuery和js语法、js处理iframe
selenium 执行jQuery/js语法 driver.execute_script(jQuery/js) 1.jQuery jQuery只支持css语法: jquery = '$(CSS).va ...
- js语法没有任何问题但是就是不走,检查js中命名的变量名,用 service-area错误,改service_area (原)
js语法没有任何问题但是就是不走,检查js中命名的变量名,用 service-area错误,改service_area
- JS 语法大全
来源http://blog.csdn.net/newegg2009/article/details/6230582 js语法2008年03月19日 星期三 11:14一.js的数据类型和变量 Java ...
- gulp-gulpfile.js语法说明
关于gulpfile文件: 直接上代码吧!! /*! * gulp * $ npm install gulp gulp-ruby-sass gulp-cached gulp-uglify gulp-r ...
- JS语法学习笔记
JS语法: JS知识点一览图 JS知识点一览图 在function中写this,在本function中可以显示,写Person则显示undefined. 在function中写Person,在func ...
- Mongodb中的js语法
定义一个变量 > var len = 10; For循环 这里的db和data都可以作为对象 save是方法 接收一个临时定义的对象 > for(var i = 0; i < len ...
- 01.JS语法规范、变量与常量
前言: 学习一门编程语言的基本步骤 (01)了解背景知识 (02)搭建开发环境 (03)语法规范 (04)常量和变量 2.JS的开发环境 (1)浏览器自带的JS解释器(js引擎) (2 ...
- webpack 之 js语法检查eslint
webpack 之 js语法检查eslint // 用来拼接绝对路径的方法 const {resolve} = require('path') const HtmlWebpackPlugin = re ...
随机推荐
- 百川sdk----自己的WebViewClient不被执行【废弃,新版本百川已修复此问题】
我在百川sdk的旺旺群中,追问这个问题N多次,一直没有人答复,哎,凡事都要靠自己..... 1.先查看下百川sdk中,是怎么处理咱们传递过去的 WebViewClient public class l ...
- Measuring Text Difficulty Using Parse-Tree Frequency
https://nlp.lab.arizona.edu/sites/nlp.lab.arizona.edu/files/Kauchak-Leroy-Hogue-JASIST-2017.pdf In p ...
- 评测parser的好坏
1.在dependency parsing中一般是用 LAS UAS 来衡量 简要说来UAS是知道是边对了(也就是它依赖的节点找对了)就算对,而LAS在前者的基础上要求更加严格,还要求边的Label也 ...
- Linux防火墙开启关闭查询
1.centos7防火墙 命令含义: –zone #作用域 –add-port=80/tcp #添加端口,格式为:端口/通讯协议 –permanent #永久生效,没有此参数重启后失效 服务与端口的启 ...
- 学习笔记DL003:神经网络第二、三次浪潮,数据量、模型规模,精度、复杂度,对现实世界冲击
神经科学,依靠单一深度学习算法解决不同任务.视觉信号传送到听觉区域,大脑听学习处理区域学会“看”(Von Melchner et al., 2000).计算单元互相作用变智能.新认知机(Fukushi ...
- linux安装Samba服务
[1].yum -y install samba安装samba [2].找到samba配置文件:vim /etc/samba/smb.conf [3].[gloabl]下面security有三种模式: ...
- Python3数据类型及转换
I. 数据类型 Python3将程序中的任何内容统称为对象(Object),基本的数据类型有数字和字符串等,也可以使用自定义的类(Classes)创建新的类型. Python3中有六个标准的数据类型: ...
- 公司内网接口ip城市查询分析
require 'rubygems' require 'json' print ARGV print "fist is :",ARGV[0] logfile="#{ARG ...
- Computer Graphics Principles And Practice (James Foley / Andries Van Dam / Morgan McGuire / David Sklar / James D. Foley 著)
1 Introduction 2 Introduction to 2D Graphics Using WPF 3 An Ancient Renderer Made Modern 4 A 2D Grap ...
- vue2-通过axios实现数据请求
1.通过axios实现数据请求 vue.js默认没有提供ajax功能 所以使用vue的时候,一般都会使用axios的插件来实现ajax与后端服务器的数据交互. 注意,axios本质上就是javascr ...