32
32

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 5 years have passed since last update.

JavaScriptで配列を値渡しをする

Last updated at Posted at 2014-05-01

JavaScirptでは、オブジェクトや配列は参照渡し。
※厳密には参照渡しでもないっぽい?

jQueryを使って配列をコピーすれば、値渡しになる。

hoge = ["bar", "fuga"];
hoge2 = $.extend(true, [], hoge);

追記

jQueryを使わなくもコピーできます。

var hoge = ['bar', 'fuga'];
var hoge2 = hoge.slice();
32
32
7

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?