How to clear an array in js

Three ways to clear an array.jpg

The first one: using the splice() method of the array

method.jpg

The second method:

Note that the length of the array in js is readable and writable. different from other languages.

Third method:

In fact, arr3 points to a new array, which is empty, so it looks like it has been emptied, but it is not actually emptying the array. Then the previous array has no other references to it and will be garbage collected.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324898647&siteId=291194637