Node.js你怎么console.log出一个对象-属性+变量?
Node.js how do you console.log out an object-property + variable?
我试图通过将变量添加到 select 属性 的 objectProperty 末尾来 console.log 得出真/假语句:(appleAmount.amount+数字)?
你是怎么做到的?
let apple = 48;
let appleAmount = {
amount0 : 20,
amount1 : 40,
amount2 : 48
}
let number = 2;
console.log(apple === appleAmount.amount+number);
在 JavaScript 中,您可以通过字符串名称访问属性,而不仅仅是通过点运算符:
console.log(apple === appleAmount[`amount${number}`]); // If your version supports interpolation
console.log(apple === appleAmount['amount' + number]);
我试图通过将变量添加到 select 属性 的 objectProperty 末尾来 console.log 得出真/假语句:(appleAmount.amount+数字)? 你是怎么做到的?
let apple = 48;
let appleAmount = {
amount0 : 20,
amount1 : 40,
amount2 : 48
}
let number = 2;
console.log(apple === appleAmount.amount+number);
在 JavaScript 中,您可以通过字符串名称访问属性,而不仅仅是通过点运算符:
console.log(apple === appleAmount[`amount${number}`]); // If your version supports interpolation
console.log(apple === appleAmount['amount' + number]);