Currently I have three arrays. AppNames which is an application Name. Number of AddOns which is the number of add ons each application is using. (Both of these arrays are used together. E.G "cirr-contentful-demo" has 1 add on).
Look Below:
var prodArrayAppName = [],
stgArrayAppName = [],
devArrayAppName = [],
prodNoAddOns = [],
stgNoAddOns = [],
devNoAddOns = [];
var appNames = ["cirr-contentful-demo", "cirr-contentful-handler-backup", "cirr-test-app"];
var numberAddOne = [1, 5, 7]
var production = [{
"id": "16",
"heroku_application": "cirr-contentful-demo",
"stage": "Production"
},
{
"id": "4",
"heroku_application": "cirr-contentful-handler-backup",
"stage": "Staging"
},
{
"id": "9",
"heroku_application": "test-backup",
"stage": "Development"
}];
What I need is to loop through the production array of objects, match the heroku_application name to the name in the appNames array. Once found check the stage type example: Production, Staging, Development.
The push the application name to the correct array. E.G Production applications to prodArrayAppName. Then grab the number of addOns that application has and put it into the correct NoOfAddons. E.G prodArrayAppName.
Meaning the end game should look like:
prodArrayAppName = [cirr-contentful-demo]
prodNoAddOns = [1]
stgArrayAppName = [cirr-contentful-handler-backu]
stgNoAddOns = [5]
devArrayAppName = [test-backup]
devNoAddOns = [7]
This Is the code I have tried so far, but so far getting no luck:
production.forEach(function(a) {
appNames.forEach(function(b) {
numberAddOne.forEach(function(c) {
if (a === b.heroku_application) {
if (b.stage === "Production") {
prodArrayAppName.push(b.heroku_application);
prodNoAddOns.push(c);
} else if (b.stage === "Staging") {
stgArrayAppName.push(b.heroku_application);
stgNoAddOns.push(c);
} else {
devArrayAppName.push(b.heroku_application);
devNoAddOns.push(c);
}
}
});
});
});
production.forEach(function(a) { appNames.forEach(function(b) { numberAddOne.forEach(function(c) { if (a === b.heroku_application){ } }); }); });I'm super stuck and some help would be appreciated.