let newArr = [];
res.data.data.forEach((address, i) => {
let index = -1;
let newDates = Date.parse(new Date(address.created_at).toLocaleDateString());
console.log(newDates);
let alreadyExists = newArr.some((newAddress, j) => {
if (newDates === newAddress.created_at) {
index = j;
return true;
}
});
if (!alreadyExists) {
newArr.push({
created_at: newDates,
id:address.id,
location: [address.title]
});
} else {
newArr[index].location.push(address.title);
}
});
newArr.map((item,index)=>{
let date = new Date(item.created_at).toLocaleString();
let newDate = date.substring(0,10);
item.created_at = newDate;
});