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] 第414天 使用delete删除数组,其长度会改变吗? #2462

Open
haizhilin2013 opened this issue Jun 2, 2020 · 5 comments
Open
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第414天 使用delete删除数组,其长度会改变吗?

3+1官网

我也要出题

@haizhilin2013 haizhilin2013 added the js JavaScript label Jun 2, 2020
@zhimianhub
Copy link

不会

@zhiyual
Copy link

zhiyual commented Jun 16, 2020

不会

@OriX0
Copy link

OriX0 commented Jun 30, 2020

delete删除数组 长度不会改变

因为 delete obj.key 是通过 key 来移除对应的值

正确且常用的方法 为arr.splice(index[,deleteCount])

@bozaigao
Copy link

长度不会改变,这里引生出另一个知识点,通过设置数组的length为0,可以清空数组。

@xiaoqiangz
Copy link

长度不会变, 例如 var arr = [1, 2, 3] delete arr[1] -> [1, ,3],如果将数组的length设为0,则会清空数组。

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

No branches or pull requests

6 participants