{"id":34,"date":"2019-06-19T07:29:53","date_gmt":"2019-06-19T07:29:53","guid":{"rendered":"http:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/"},"modified":"2019-06-19T07:29:53","modified_gmt":"2019-06-19T07:29:53","slug":"javascript-group-object-by-its-properties","status":"publish","type":"post","link":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/","title":{"rendered":"Javascript group object by its properties"},"content":{"rendered":"<p>In this small article I will show you how you can easily group the object by its properties.<\/p>\n<p>Below is the function code to group the object by its properties.<\/p>\n<pre><code>Common = {\n \t_groupBy:function(list,props) {\n\t\treturn list.reduce((a, b) =&gt; {(a[b[props]] = a[b[props]] || []).push(b);return a;}, {});\n\t},\n}<\/code><\/pre>\n<pre>Here I have this kind of format in my response where the date might be same but not the time. In this example I am going to use the sessionDate properties from the below response screenshot.<\/pre>\n<figure><img decoding=\"async\" src=\"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png\" sizes=\"(max-width: 766px) 100vw, 766px\" srcset=\"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png 766w, https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image-300x171.png 300w\" alt=\"\"><\/figure>\n<p>With the below code now I can see new output in response. You can see how with date it is trying to create an array grouping other object with same date.<\/p>\n<pre><code>var sessionData=Common._groupBy(response.data.results,'sessionDate');\nconsole.log(sessionData)<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image-1.png\" sizes=\"(max-width: 906px) 100vw, 906px\" srcset=\"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image-1.png 906w, https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image-1-300x46.png 300w, https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image-1-768x117.png 768w\" alt=\"\"><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this small article I will show you how you can easily group the object by its properties. Below is the function code to group the object by its properties. Common = { _groupBy:function(list,props) { return list.reduce((a, b) =&gt; {(a[b[props]] = a[b[props]] || []).push(b);return a;}, {}); }, } Here I have this kind of format [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Javascript group object by its properties - Santosh Kumar Shah<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Javascript group object by its properties - Santosh Kumar Shah\" \/>\n<meta property=\"og:description\" content=\"In this small article I will show you how you can easily group the object by its properties. Below is the function code to group the object by its properties. Common = { _groupBy:function(list,props) { return list.reduce((a, b) =&gt; {(a[b[props]] = a[b[props]] || []).push(b);return a;}, {}); }, } Here I have this kind of format [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/\" \/>\n<meta property=\"og:site_name\" content=\"Santosh Kumar Shah\" \/>\n<meta property=\"article:published_time\" content=\"2019-06-19T07:29:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png\" \/>\n<meta name=\"author\" content=\"Santosh Kumar Shah\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Santosh Kumar Shah\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/\",\"url\":\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/\",\"name\":\"Javascript group object by its properties - Santosh Kumar Shah\",\"isPartOf\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png\",\"datePublished\":\"2019-06-19T07:29:53+00:00\",\"author\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f\"},\"breadcrumb\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#primaryimage\",\"url\":\"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png\",\"contentUrl\":\"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/santosh-shah.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Javascript group object by its properties\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#website\",\"url\":\"https:\/\/santosh-shah.com\/blog\/\",\"name\":\"Santosh Kumar Shah\",\"description\":\"JavaScript Developer\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/santosh-shah.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f\",\"name\":\"Santosh Kumar Shah\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g\",\"caption\":\"Santosh Kumar Shah\"},\"description\":\"I am JavaScript developer.\",\"sameAs\":[\"https:\/\/santosh-shah.com\/blog\"],\"url\":\"https:\/\/santosh-shah.com\/blog\/author\/sks7yu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Javascript group object by its properties - Santosh Kumar Shah","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/","og_locale":"en_US","og_type":"article","og_title":"Javascript group object by its properties - Santosh Kumar Shah","og_description":"In this small article I will show you how you can easily group the object by its properties. Below is the function code to group the object by its properties. Common = { _groupBy:function(list,props) { return list.reduce((a, b) =&gt; {(a[b[props]] = a[b[props]] || []).push(b);return a;}, {}); }, } Here I have this kind of format [&hellip;]","og_url":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/","og_site_name":"Santosh Kumar Shah","article_published_time":"2019-06-19T07:29:53+00:00","og_image":[{"url":"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png","type":"","width":"","height":""}],"author":"Santosh Kumar Shah","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Santosh Kumar Shah","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/","url":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/","name":"Javascript group object by its properties - Santosh Kumar Shah","isPartOf":{"@id":"https:\/\/santosh-shah.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#primaryimage"},"image":{"@id":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#primaryimage"},"thumbnailUrl":"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png","datePublished":"2019-06-19T07:29:53+00:00","author":{"@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f"},"breadcrumb":{"@id":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#primaryimage","url":"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png","contentUrl":"https:\/\/santosh-shah.com\/wp-content\/uploads\/2019\/06\/image.png"},{"@type":"BreadcrumbList","@id":"https:\/\/santosh-shah.com\/blog\/javascript-group-object-by-its-properties\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/santosh-shah.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Javascript group object by its properties"}]},{"@type":"WebSite","@id":"https:\/\/santosh-shah.com\/blog\/#website","url":"https:\/\/santosh-shah.com\/blog\/","name":"Santosh Kumar Shah","description":"JavaScript Developer","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/santosh-shah.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f","name":"Santosh Kumar Shah","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g","caption":"Santosh Kumar Shah"},"description":"I am JavaScript developer.","sameAs":["https:\/\/santosh-shah.com\/blog"],"url":"https:\/\/santosh-shah.com\/blog\/author\/sks7yu\/"}]}},"_links":{"self":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}