LoginSignup
42
32

More than 5 years have passed since last update.

参照を切らずに配列を空にする

Posted at
var a = new Array(1000);
var b = a;

配列を空にする時

a = [];
console.log(b); // Array(1000)

空の配列を代入すると参照が切れてしまうので、
切りたくない場合は

a.splice(0, a.length);
console.log(b); // []
42
32
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
32