Pushing to array that is inside an object

Input is 3 rows with ids
1) a-123123
2) a-543543
3) b-543543


$('.bg_upload_row').each(function(){

	var row_id = $(this).attr('id').split('-');
	// row_id[0] is the type
	// row_id[1] is the user ID

	// Push user ID into user set if it isn't already there
	if( $.inArray( row_id[1], user_set ) === -1 ){
		user_set[row_id[1]] = [];
	}

	// Push upload type into uploaded set for user
	user_set[row_id[1]].push(row_id[0]);
});

console.log( user_set );

What I’m hoping for would be an object with arrays of types, like this:


{
	"123123": ["a"],
	"543543": ["a","b"]
}

But the second type is overwriting the first, so the arrays are always an array with a single value, like this:


{
	"123123": ["a"],
	"543543": ["b"]
}

And I’m not even sure if I’m going about things the right way for what I’m doing. Basically, the types are upload types, and the user must upload a specific set of types, or they can’t get past a certain point. I think if I can get this object of arrays created I’ll be able to further evaluate if all of the users have all of their uploads, but I’m not successful yet. I’m used to PHP, and making a multi-dimensional array in PHP is a piece of cake, but javascript is not so friendly for me.

The problem is your IF statement, the $.inArray method checks for values within the array but not the keys themselves so there for the new array is been created everytime. Instead you should use the below:

if (!row_id[1] in user_set) {
    user_set[row_id[1]] = [];
}