0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JavaScript 配列=配列(Array=Array) 

Last updated at Posted at 2022-12-10
Array
var a = [];
var b = a;

という状況になると,bはaの引用となる,C言語のpointer(*)と同じ原理.
つまり,以下の状況になる

Array
b[0] = 1;
a[0]     // ==> 1 となる.
a === b   //==> true

もしbを新たな配列にしたい場合,for循環で要素を一個づつ渡すべき.

補足:
このような状況は,変数bが別の変数を与えられると,変数aに影響がない.
例は,「@think49」さんのコメントに参照.

0
0
1

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?