LoginSignup
2
2

More than 1 year has passed since last update.

【Javascript】Switch文を書かずに、特定のパターンのときに処理を切り分けたいときの書き方

Posted at
const statusLabel = returnLabel(1)  // 成功

function returnLabel(labelNumber) {
  const label = {
    0: '成功',
    1: 'キャンセル',
    2: 'エラー'
  }

  return label[labelNumber]
}
2
2
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
2
2