-
Notifications
You must be signed in to change notification settings - Fork 894
New issue
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
Day74:写出执行结果,并解释原因 #122
Comments
// 答案 //解析 1)reverse 2)slice |
搞了这么,第一次直到 reverse 会返回数组的引用! |
arr1=['a','b'] //切割 |
答案是:3,[ [ 'a', 'b', 'c' ] ],3,[ [ 'a', 'b', 'c' ] ] 1)reverse MDN 上对于 reverse() 的描述是酱紫的: The reverse method transposes the elements of the calling array object in place, mutating the array, and returning a reference to the array. reverse 方法颠倒数组中元素的位置,改变了数组,并返回该数组的引用。 2)slice slice() 方法返回一个新的数组对象,这一对象是一个由 begin 和 end 决定的原数组的浅拷贝(包括 begin,不包括end)。原始数组不会被改变。 如果该参数为负数, 则它表示在原数组中的倒数第几个元素结束抽取。 slice(-2,-1) 表示抽取了原数组中的倒数第二个元素到最后一个元素(不包含最后一个元素,也就是只有倒数第二个元素)。但是需要注意的是slice()返回的是一个浅拷贝的数组,但是由于最后一个elements是一个数组即[ 'a', 'b', 'c' ],所以答案应该是一个二维数组即[[ 'a', 'b', 'c' ]] |
The text was updated successfully, but these errors were encountered: