0
点赞
收藏
分享

微信扫一扫

js清空数组的正确做法

343d85639154 2022-11-24 阅读 143


Emptying an array is a common JavaScript task but too often I see the task performed in the incorrect way. Many times developers will create a new array:

myArray = []; // bad

That isn’t the optimal way to get a fresh array; to truncate an array, and thus empty it, you should set the length property to zero:(正确的做法)

myArray.length = 0; // good!


举报

相关推荐

0 条评论