I am trying to convert an array(with email addresses) in to object. How to insert values in value array for one key?
var list = [
"[email protected]", "[email protected]",
"[email protected]", "[email protected]"
];
(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 also want to add like
{
"gmail.com" : [3],//1+1+1
"yahoo.com" : [4]//1+1+1+1
}