且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用变量名和字符串组合创建 Javascript 变量

更新时间:2023-01-19 11:47:01

如果您在全局命名空间中,请使用:

If you're in the global namespace, use this:

window['vid' + num] = 1;

但这是一个非常好的数组用例:

but this is a really good use case for an array:

var numbers = [0, 0, 0];
var num = 1;

numbers[num] = 1;