[英]Is there a way to use a string inside of a variable to refer to an object property?
基本上我想使用一個對象來保存某些日期。 例如:
var date {
jan26: 'Today this happened'
};
然后獲取當前日期並將其放入字符串中。 例如: var today = 'jan26';
。 然后使用它來引用對象屬性:例如: alert(date.today);
有什么辦法嗎?
使用以下代碼: date[today]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.