Is it possible to modify the object that is pushed into an array using a function within the push method?
I have a method that searches for a match between profile.id and keywordId, and then pushes the matching keywordId into an array. How can I update this push method to include additional properties in the object being pushed?
I want to push the following object into the array:
array.push({ id: profile.id, keyID: keywordID, name: profile.name });
However, I am unsure how to achieve this with the current code:
array.push(findKeywordProfile(profile.id));
Here is my method for creating the array:
function getKeywordProfiles(brandProfilesArray) {
var array = [];
brandProfilesArray.forEach(function (profile) {
array.push(findKeywordProfile(profile.id));
})
return $q.all(array);
}
This is the method called during the array.push operation:
function findKeywordProfile(brandProfileID) {
var keywordProfileID = $q.defer();
pullSocialMediaData('list_keyword_profiles.json').then(function (data) {
var keywordProfileInstance = data.filter(function (keyword) {
return keyword.brand_profile_id === brandProfileID;
});
keywordProfileID.resolve(keywordProfileInstance[0].id);
});
return keywordProfileID.promise;
}
Thank you!