I have this array of objects. Every object has a unique value label. I would like to compare them by the label value and if the value matches a new object with the unique value should be created.

```js
  var test = [{
          isnewLanguage: "false",
          label: "label1",
          languages: [{
          language: "English",
          questions: [{
          choices: "choices1",
          fields: "false",
          mainText: "MAinText1",
          subText: "SubText1"
        }]
        }],
          numberOfChoices: "5"
        }, {
          isnewLanguage: "false",
          label: "label2",
          languages: [{
          language: "English",
          questions: [{
          choices: "choices2",
          fields: "false",
          mainText: "MAinText2",
          subText: "SubText2"
        }]
        }],
          numberOfChoices: "5"
        }, {
          isnewLanguage: "true",
          label: "label1",
          languages: [{
          language: "Italian",
          questions: [{
          choices: "choicesItalian1",
          fields: "false",
          mainText: "MainTextItalian1",
          subText: "SubTextItalian1"
        }]
        }],
          numberOfChoices: "false"
        }, {
          isnewLanguage: "true",
          label: "label2",
          languages: [{
          language: "Italian",
          questions: [{
          choices: "choicesItalian2",
          fields: "false",
          mainText: "MAinTextItalian2",
          subText: "SubTextItalian2"
        }]
        }],
          numberOfChoices: "false"
        }, {
          isnewLanguage: "true",
          label: "label1",
          languages: [{
          language: "Chinece",
          questions: [{
          choices: "choicesChinece",
          fields: "false",
          mainText: "MainTextChinece1",
          subText: "SubTextChinece1"
        }]
        }],
          numberOfChoices: "false"
        }, {
          isnewLanguage: "true",
          label: "label2",
          languages: [{
          language: "Italian",
          questions: [{
          choices: "choicesItalian2",
          fields: "false",
          mainText: "MAinTextItalian2",
          subText: "SubTextItalian2"
        }]
        }],
          numberOfChoices: "false"
        }]

```

Below is the required structure. Each object with the same label value should be appended to one object with the new languages.

```js
var theRequiredStructure = [{
      isnewLanguage: "true",
      label: "label1",
      languagesTest: [{
      language: "English",
      questions: [{
      choices: "choices1",
      fields: "false",
      mainText: "MAinText1",
      subText: "SubText1"
    }]
    }, {
      language: "Italian",
      questions: [{
      choices: "choicesItalian1",
      fields: "false",
      mainText: "MainTextItalian1",
      subText: "SubTextItalian1"
    }]
    }, {
      language: "Chinece",
      questions: [{
      choices: "choicesChinece",
      fields: "false",
      mainText: "MainTextChinece1",
      subText: "SubTextChinece1"
    }]
    }],
      numberOfChoices: "false"
    },
    {
      isnewLanguage: "true",
      label: "label2",
      languagesTest: [{
      language: "English",
      questions: [{
     choices: "choices2",
      fields: "false",
      mainText: "MAinText2",
      subText: "SubText2"
    }]
    }, {
      language: "Italian",
      questions: [{
      choices: "choicesItalian2",
      fields: "false",
      mainText: "MainTextItalian2",
      subText: "SubTextItalian2"
    }]
    }, {
      language: "Chinece",
      questions: [{
      choices: "choicesChinece2",
      fields: "false",
      mainText: "MainTextChinece2",
      subText: "SubTextChinece2"
    }]
    }],
      numberOfChoices: "false"
    }
```

Here is my work but obviously it works only for the first element. How can I achieve the required structure for all elements? I prefer mostly ES5 solutions which is understandable to me. Thanks for taking the time

```js
var test = [{
      isnewLanguage: "false",
      label: "label1",
      languages: [{
      language: "English",
      questions: [{
      choices: "choices1",
      fields: "false",
      mainText: "MAinText1",
      subText: "SubText1"
    }]
    }],
      numberOfChoices: "5"
    }, {
      isnewLanguage: "false",
      label: "label2",
      languages: [{
      language: "English",
      questions: [{
      choices: "choices2",
      fields: "false",
      mainText: "MAinText2",
      subText: "SubText2"
    }]
    }],
      numberOfChoices: "5"
    }, {
      isnewLanguage: "true",
      label: "label1",
      languages: [{
      language: "Italian",
      questions: [{
      choices: "choicesItalian1",
      fields: "false",
      mainText: "MainTextItalian1",
      subText: "SubTextItalian1"
    }]
    }],
      numberOfChoices: "false"
    }, {
      isnewLanguage: "true",
      label: "label2",
      languages: [{
      language: "Italian",
      questions: [{
      choices: "choicesItalian2",
      fields: "false",
      mainText: "MAinTextItalian2",
      subText: "SubTextItalian2"
    }]
    }],
      numberOfChoices: "false"
    }, {
      isnewLanguage: "true",
      label: "label1",
      languages: [{
      language: "Chinece",
      questions: [{
      choices: "choicesChinece",
      fields: "false",
      mainText: "MainTextChinece1",
      subText: "SubTextChinece1"
    }]
    }],
      numberOfChoices: "false"
    }, {
      isnewLanguage: "true",
      label: "label2",
      languages: [{
      language: "Italian",
      questions: [{
      choices: "choicesItalian2",
      fields: "false",
      mainText: "MAinTextItalian2",
      subText: "SubTextItalian2"
    }]
    }],
      numberOfChoices: "false"
    }]

var theLanguagesTest = [];
var obj = {};
for (var i = 0; i < test.length; i++) {
  if (test[0].label == test[i].label) {
    obj = test[i]

  }
  for (var j = 0; j < test[i].languages.length; j++) {
    if (test[0].label == test[i].label) {
      theLanguagesTest.push(test[i].languages[j])
      obj.languagesTest = theLanguagesTest
    }
  }
  delete test[i].languages;
  delete test[i].questions;
}

console.log(obj)
```