I am attempting to transform an array containing email addresses into an object. How can I insert values in the value array for a single key?
var list = [
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6903060107291008010606470a0604">[email protected]</a>", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a584b47436a4d474b434604494547">[email protected]</a>",
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f05001c072f160e070000410c0002">[email protected]</a>", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abc9cac7ceebccc6cac2c785c8c4c6">[email protected]</a>"
];
(function() {
var obj1 = {};
for (var a = 0, b = list.length; b > a; a++) {
var str = list[a].split("@");
var arr = [];
arr.push(str[0]);
if (!(str[1] in obj1)) {
obj1[str[1]] = []; //arr.push(str[0])];
}
Object.values(obj1[str[1]]).push(str[0])
};
console.log(obj1);
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
{
"gmail.com" : ["a","b","c"],
"yahoo.com" : ["de","e","f"]
}
I would also like to include this as well
{
"gmail.com" : [3],//1+1+1
"yahoo.com" : [4]//1+1+1+1
}