JS小技巧(一)
HuangXiZhou opened this issue · comments
Amigooo commented
JS删除数组
在JavaScript中,删除一个数组,应该使用arr.length = 0
,而不是delete arr
使用arr.length = 0
使用delete arr
为什么?
其实在MDN Web Docs中已经给出了答案:
The
delete
operator removes a property from an object.Parameters
object
:
The name of an object, or an expression evaluating to an >object.
property
:
The property to delete.