gpt4 book ai didi

javascript - 将现有的 javascript 数组分配给对象表示法中的属性

转载 作者:行者123 更新时间:2023-11-30 23:51:55 24 4
gpt4 key购买 nike

我正在本地化一个菜单,并且我想以这种方式将声明的数组分配给对象属性:

var menuListLocal=["Home","Play","Options","Exit"];

var menu_Controller={
_menuList: menuListLocal,
// .... //
}

抱歉,如果太明显了。

谢谢。

最佳答案

记住 ropstah 的评论,你所拥有的应该有效。

var menuListLocal=["Home","Play","Options","Exit"];

var menu_Controller={
_menuList: menuListLocal,
_other: 'Something'
};

使用示例:

var home = menuListLocal._menuList[0];

关于javascript - 将现有的 javascript 数组分配给对象表示法中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1307244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com