要在JavaScript中清空数组,请将变量设置为empty:
arr = []
您可以尝试运行以下代码以清空JavaScript中的数组:
<html> <head> <title>JavaScript Arrays</title> </head> <body> <script> var arr = ["orange", "mango", "banana", "sugar", "tea"]; document.write("<br />Original array: " + arr ); arr = []; document.write("<br />Current array: " + arr ); </script> </body> </html>