LoginSignup
9
8

More than 5 years have passed since last update.

配列の要素を展開して関数の引数にする

Posted at

配列args = [1, 2, 3]と、
関数hoge = function(){console.log(arguments);}があって、
argsの要素をhogeの引数としてhoge(1, 2, 3)って渡したい。

普通にhoge(args)ってやると{ '0': [ 1, 2, 3 ] }ってなる。

Function.apply

hoge.apply(this, args)
{ '0': 1, '1': 2, '2': 3 }

9
8
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
9
8