Below is the code snippet where I am attempting to dynamically construct an associative array in angularJs:
$scope.details = {"profilesFound": [
"https: //twitter.com/alexandreagular",
"https: //twitter.com/?profile_id=46130006",
"https: //facebook.com/1290628666",
"https: //twitter.com/intent/user?user_id=84326171",
"https: //www.linkedin.com/in/alex",
"https: //www.linkedin.com/in/alexandreagular",
"https: //www.facebook.com/alexandre.agular",
"https: //www.facebook.com/alexandre"
]};
$scope.socialProfiles = [];
var spLength = $scope.details.profilesFound.length;
for(var i=0;i<spLength;i++){
var url = $scope.details.profilesFound[i];
var domain = url.replace('.com','').replace('http://www.','').replace('https://www.','').replace('http://','').replace('https://','').split(/[/?#]/)[0];
$scope.socialProfiles[domain]=url;
}
My desired array construction is as follows:
"profilesFound":{
"facebook":[
"https://facebook.com/1290628666",
"https://www.facebook.com/alexandre.agular"
],
"twitter":[
"https: //twitter.com/alexandreagular",
"https: //twitter.com/?profile_id=46130006",
"https: //twitter.com/intent/user?user_id=84326171"
],
"linkedin":[
"https: //linkedin.com/1290628666",
"https: //www.linkedin.com/alexandre.agular"
]
}
However, the resulting output I am getting is:
[twitter: "https://twitter.com/intent/user?user_id=84326171", facebook: "https://www.facebook.com/alexandre.agular", linkedin: "https://www.linkedin.com/in/alexandreagular"]
Any solutions or suggestions would be greatly appreciated. Thank you.