How to Empty an Array in JavaScript
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Use the
length
PropertyYou can simply use the array's length property to empty an array in JavaScript.
Let's take a look at an example to understand how it basically works:
You can alternatively use the square bracket notation to empty an array, such as arr1 = [], if you don't have any references to the original array arr1 anywhere else in your code, because it creates a brand new empty array instead of emptying the original array, as you can see here:
need an explanation for this answer? contact us directly to get an explanation for this answer