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

[JavaScript] 複数の戻り値を個別の変数に入れたい時

Posted at

#複数の戻り値を別々の変数にいれる場合の手順

  1. 配列またはオブジェクトとして値をまず一つにまとめる
  2. 分割代入を利用して、それぞれの変数に代入する
function getMaxMin(...nums) {
  return [Math.max(...nums), Math.min(...nums)]; 
}

let result = getMaxMin(5, 1-, 10, 20, 50)
console.log(50, -1) 

//これをそれぞれの変数にいれる!分割代入を使う!
let [max, min] = getMaxMin(5, 1-, 10, 20, 50); 
console.log(max) //50 
console.log(min) //-1
0
0
0

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?