英文:
Beginner help on arrays
问题
以下是您要翻译的内容:
你好,首先感谢您今天查看我的帖子!我在开发方面还相对新手,但在过去的几周里,我一直在参加各种在线课程并研究JavaScript和Node.js。
以下数组是我当前项目中的重要部分,
let row = [button_one, button_two, button_three, button_delete];
每个变量都在我的JSON配置文件中有自己的位置,如下所示,
{
"Button_One": true,
"Button_Two": false,
"Button_Three": false
}
我的计划是只在JSON文件中将相应的按钮设置为true,然后它们会出现在数组中。我相信这是可能的,但这不是我目前遇到的技巧,所以希望有人可以帮助我。
如果我的问题过于简单或愚蠢,让我道歉。正如我提到的,我是新手,目前感到有点吓人,提前感谢您的帮助!
截止目前,我还没有逻辑上的解决方案来解决我的问题。因此,我还没有尝试解决我的问题!
英文:
Hello and firstly thanks for checking out my post today! I'm fairly new to developing as a whole but over the past few weeks have been taking various online courses and reading into javascript and nodejs.
The following array is an important piece in my current project,
let row = [button_one, button_two, button_three, button_delete];
and each variable has it's own place in my json configuration files, which looks as follows,
{
"Button_One": true,
"Button_Two": false,
"Button_Three": false
}
My plan was to only have the corresponding buttons set to true in the json file appear in the array. I'm sure this is possible however it's not a technique I have come across yet, so hopefully somebody can help me.
Let me apologise if my question is painfully simple, or stupid. As I mentioned I'm new the developing and it's all a little intimidating at the moment, thanks for the help in advance!
I haven't logically thought of a solution to my problem yet. Therefore I have had no attempts to solve my problem!
答案1
得分: 0
const object = {
"Button_One": true,
"Button_Two": false,
"Button_Three": false
};
let arr = [];
for (const el in object) {
if (object[el] === true) {
arr.push(el)
}
}
英文:
const object = {
"Button_One": true,
"Button_Two": false,
"Button_Three": false
};
let arr = [];
for (const el in object) {
if (object[el] === true) {
arr.push(el)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论