I have some angular code that I am working on. The goal is to use as little angular 1.x functionality as possible since this will be getting refactored soon.
I am comparing an array
let subscription = [
"Cinemax Subscription",
"Disney Subscription",
"Encore Subscription",
"Epix Subscription",
"HBO Subscription",
"MLB Subscription",
"NBA Subscription",
"NHL Subscription",
"Division"
]
to an array of objects with a key value relationship that houses another array.
let profiles = [
{
name:"1+ Adults in Household",
qualifiers: [
{
name: 'Number of adults in the household'
}
]
},
{
name: '75k',
qualifers: [
{
name: 'Division'
},
{
name: 'Income'
}
]
},
{
name: 'Time Warner',
qualifers: [
{
name: 'Division'
}
]
}
]
I am having a difficult time with the indexes and the looping of this.
let = profilesFiltered = [];
Initially I tried to use a filter and angular.for Each to compare the arrays.
let filteredProfiles = subscription.filter( function (src) {
angular.forEach(profiles, function (key, index) {
if(src === key.qualifiers[index].name) {
profilesFiltered.push(key);
}
})
});
I am seeing inside the if statement that
key.qualifiers[index].name // 'Number of adults in the household'
Starts out correct in comparison to
subscription[0] // however, it will continue to 1 on the first object which isn't there.
I see how it is starting to fail. But I am not sure how to get properly loop through the qualifiers in the **profiles ** array.
The desired result is as those house Division which is the last array item in the index.
profilesFiltered = [
{
name: '75k',
qualifers: [
{
name: 'Division'
},
{
name: 'Income'
}
]
},
{
name: 'Time Warner',
qualifers: [
{
name: 'Division'
}
]
}
]
Any feedback is greatly appreciated at this point.
Thanks