I have 2 array of objects one for USA and another for Canada. The data goes in the following way
const data = [
{country: {cntryShortName:"USA"}}
{country: {cntryShortName:"USA"}}
{country: {cntryShortName:"CAN"}}
{country: {cntryShortName:"USA"}}
{country: {cntryShortName:"CAN"}}
{country: {cntryShortName:"CAN"}}
{country: {cntryShortName:"USA"}}
{country: {cntryShortName:"USA"}}
]
Here I am expecting to divide the data into 2 like as
USA:
.....
.....
CAN:
.....
.....
This is what I've tried
const allData = data.filter(item => item.country)
Here I'm getting all the array data but I want to sort it based on country name but hard coding isn't expected. Any optimal solution