We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
类数组概念:
拥有length属性和若干索引属性的对象就被称为类数组,它和数组类似,但是不能调用数组的方法。
length
常见类数组:
DOM方法返回的批量的DOM集合, arguments,另外函数也可以被看为是类数组,因为它拥有length属性,length的值就是它可接收的参数的个数。
DOM
arguments
转换为数组:
先让我们来定义一个类数组:
function test () { console.log(Array.isArray(arguments)) // false } test('霖', '呆', '呆')
然后来看看可以有哪几种转换方法:
call
slice
[].slice.call(arguments) // 当然也可以是这样,因为slice是Array.prototype上的方法 Array.prototype.slice.call(arguments)
splice
[].splice.call(arguments)
apply
concat
[].concat.apply(arguments)
Array.from()
Array.from(arguments)
...
[...arguments]
来写个简写吧:
slice + call
splice + call
concat + apply
Array.from
不过貌似这个不用特意去记,想一下数组有哪些方法可以用基本就能想起来了。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
转换类数组的几种方式
类数组概念:
拥有
length
属性和若干索引属性的对象就被称为类数组,它和数组类似,但是不能调用数组的方法。常见类数组:
DOM
方法返回的批量的DOM
集合,arguments
,另外函数也可以被看为是类数组,因为它拥有length
属性,length
的值就是它可接收的参数的个数。转换为数组:
先让我们来定义一个类数组:
然后来看看可以有哪几种转换方法:
call
和数组的slice
方法:call
和数组的splice
方法:apply
和数组的concat
方法:Array.from()
:...
展开操作符:来写个简写吧:
slice + call
splice + call
concat + apply
Array.from
...
不过貌似这个不用特意去记,想一下数组有哪些方法可以用基本就能想起来了。
The text was updated successfully, but these errors were encountered: