将函数的参数编号用作变量

时间:2019-10-17 11:38:53

标签: javascript

我正在尝试使用传递给函数的数字来定位我拥有的许多不同变量。变量是button1,button2,button3等。我将数字作为参数传递,但不确定如何用数字替换变量。

function madRunner(number) {    
  // ie ideally I can add in the number instead of 3!
  Button3Value = parseInt(e.target.price);

  // I was thinking something like this??
  `Button${number}Value` = parseInt(e.target.price);
}

0 个答案:

没有答案
相关问题