js create object with properties
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
js create object with properties
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
array of objects create common key as a property and create array of objects
var data = [{ message: 'This is a test', from_user_id: 123, to_user_id: 567 }, { message: 'Another test.', from_user_id: 123, to_user_id: 567 }, { message: 'A third test.', from_user_id: '456', to_user_id: 567 }],
groups = Object.create(null),
result;
data.forEach(function (a) {
groups[a.from_user_id] = groups[a.from_user_id] || [];
groups[a.from_user_id].push(a);
});
result = Object.keys(groups).map(function (k) {
var temp = {};
temp[k] = groups[k];
return temp;
});
console.log(result);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us