Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js json groupby prop

var myJsonFromSQL = [{id:1, cat:'test1'},{id:2, cat:'test1'},
                     {id:3, cat:'test2'},{id:4, cat:'test2'}];

// 1 LINE CODE:
//'Set' deletes/do not consider duplicates
const arr_cat =  [...new Set(myJsonFromSQL.map(i => i.cat))];
//RESULT:
You will get an array with the property values grouped:
arr_cat   ['test1','test2']
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery 3.6.0 cdn 
Javascript :: how to get array from items quantity 
Javascript :: javascript format seconds into minutes and second 
Javascript :: discord.js send message to specific channel 
Javascript :: js every x seconds 
Javascript :: js save files 
Javascript :: jquery get multiple input values by name 
Javascript :: node wrangler preview 
Javascript :: firebase react router page not found on page refresh 
Javascript :: js alphabets array 
Javascript :: jquery change text color 
Javascript :: jquery debounce 
Javascript :: multi-line javascript 
Javascript :: call javascript function after div load 
Javascript :: document get element by id radio button 
Javascript :: js check if element hidden 
Javascript :: eliminar el ultimo caracter de un string javascript 
Javascript :: Truncate a string-Javascript 
Javascript :: how to get custom attribute value in react 
Javascript :: transform javascript 
Javascript :: isempty is not defined 
Javascript :: window vue remove event listener 
Javascript :: detect system dark mode javascrip 
Javascript :: make select option selected javascript 
Javascript :: javascript check if number is integer 
Javascript :: react check if in mobile 
Javascript :: chartjs stacked bar show total 
Javascript :: timestamps in mongoose 
Javascript :: Unexpected token a in JSON at position 
Javascript :: how to make div visible and invisible in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =