Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

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);
Comment

PREVIOUS NEXT
Code Example
Typescript :: how to get all arrangments python 
Typescript :: python fancy way to get arguments from the command line 
Typescript :: function in c that converts current time in timezone 
Typescript :: nestjs called every X second method 
Typescript :: number of elements in circular queue 
Typescript :: testing with limited information 
Typescript :: checked a element is focused with its key pressed 
Typescript :: to move previous month 
Typescript :: economic tracking portfolio construction 
Typescript :: get_refreshed_fragments too long to load 
Typescript :: group list into sublists python 
Typescript :: modify objects using dot notation 
Typescript :: why do we use #Email in angular with ngmodel 
Typescript :: why are my fonts and logo not appearing before I sign in asp.net 
Typescript :: yup validation typescript 
Typescript :: generic function typescript 
Typescript :: split a column of lists pandas 
Typescript :: what are the three ways for a developer to execute tests in an org 
Typescript :: Number of power set of {a, b}, where a and b are distinct elements. 
Typescript :: google fonts roboto 
Cpp :: how to use python sleep function on c++ 
Cpp :: underline in latex 
Cpp :: include all libraries in c++ 
Cpp :: messagebox windows 
Cpp :: how to cehck if list has element c++ 
Cpp :: how to make string get spaces c++ 
Cpp :: file descriptor linux c++ 
Cpp :: retourner pointeur de type qstringlist qt 
Cpp :: how to know if two vertexes are connected in graph c++ 
Cpp :: c++ default array value not null 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =