I have to do something like left join in sql in node with JSON data. Actually, on componentWillReceiveProps react (if it's changing anything).
my state:
const dayList = {
"2017-11-08": [],
"2017-11-09": [],
"2017-11-10": [],
"2017-11-11": [],
"2017-11-12": [],
"2017-11-13": []
}
my data to join:
const visit = {
"2017-11-11": "10:30",
"2017-11-12": "10:00",
"2017-11-12": "10:30"
}
And in componentdidmount i need to setState so that as result get that:
const dayList = {
"2017-11-08": [],
"2017-11-09": [],
"2017-11-10": [],
"2017-11-11": ["10:30"],
"2017-11-12": ["10:00","10:30"],
"2017-11-13": []
}
I know how to achieve it with .map, and another loop inside with if statement. But I am sure that there is a better approach. What may you suggest?