变量创建增加以将对象传递给我的对象的对象(在论坛上找不到)JavaScript

问题描述 投票:0回答:1

我想创建一个可以递增的变量,这将允许我传入我的对象的对象,以1到1显示每个集团(例如P1 => P2,P2 => P3等...等等

This.question = {p1: {…}, p2: {…}, p3: {…}, p4: {…}, p5: {…}, …} (etc)

我的代码:

var affichePage = this.questionnaire.Profil;
      for(var question in this.questionnaire.Profil["p2"]){
        this.current=this.questionnaire.Profil["p2"][question];
        console.log(question, " -> " + this.questionnaire.Profil);
        break;
}`
javascript
1个回答
0
投票

var This = {};
This.question = { p1: { a: "p1" }, p2: { a: "p2" }, p3: { a: "p3" }, p4: { a: "p4" }, p5: { a: "p5" } };

for (var question in This.question) {
  if (This.question.hasOwnProperty(question)) {
    console.log(question + " -> " + This.question[question].a);
  }
}

如果我理解你的要求正确,这个片段将有助于解决你的问题。只需根据你的要求改变“a”属性。

© www.soinside.com 2019 - 2024. All rights reserved.