Skip to content
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

【深入理解JS核心技术】5. 数组切片方法的目的是什么 #17

Open
webVueBlog opened this issue Apr 30, 2022 · 0 comments

Comments

@webVueBlog
Copy link
Owner

slice()方法将数组中的选定元素作为新数组对象返回。它选择从给定的 start 参数开始的元素,并在给定的可选 end 参数处结束,不包括最后一个元素。如果您省略第二个参数,那么它会一直选择到最后。

let arrayIntegers = [1, 2, 3, 4, 5];
let arrayIntegers1 = arrayIntegers.slice(0, 2); // returns [1,2]
let arrayIntegers2 = arrayIntegers.slice(2, 3); // returns [3]
let arrayIntegers3 = arrayIntegers.slice(4); //returns [5]

注意: Slice 方法不会改变原始数组,但它会将子集作为新数组返回。

未完结!更多内容尽情期待下一节~

【深入理解JS核心技术】欢迎各位观众老爷,求点赞,求关注,求转发~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant