我正在在node.js的一个程序(JavaScript的),我想它来与在一个变量名称的数组,因此,像这样添加阵列是在名称的变量
const name = "test"
const name = ["Contents", "Here"]; // Trying to make an array called the name
// stored in the "name" variable
谢谢!
我正在在node.js的一个程序(JavaScript的),我想它来与在一个变量名称的数组,因此,像这样添加阵列是在名称的变量
const name = "test"
const name = ["Contents", "Here"]; // Trying to make an array called the name
// stored in the "name" variable
谢谢!
您可以使用对象中的属性名称做到这一点。但是,AFAIK,你需要像eval()
这样的数组来完成它(并且你不应该使用eval()
)。
下面是它如何与一个对象去:
var myObject = {};
const name = "test"
myObject[name] = ["Contents", "Here"];
// Test
console.log(myObject.test);
console.log(myObject[name]);
console.log("Does object have a 'test' property? " + (name in myObject && name === "test"));
const var_name = "test"
const arr_name.push(var_name);
console.log(arr_name)?
我不确信此代码将满足您的需求。
所以,在上面的例子中,你想创建一个名为'test'的'const'? –
'global [name] = [“Contents”,“Here”];'? –
@JaromandaX是的,但ick! –