I am trying to save an API payload to a dictionary. The API data model has the attributes “category”, “id” and “name”.
let apiPayload = [];
(async () => {
let fetchValue = await
fetch('https://asia-southeast1-citric-pager-319712.cloudfunctions.net/gcp-simple-api').then(response => {
if (response.ok) {
return response.json();
}
throw response;
}).then(data => {
return data;
}).catch(error => console.log(error));
console.log('fetchValue', fetchValue);
let dictionary = Object.assign({}, ...fetchValue.map((x) => ({
[x.category]: [x]
})));
console.log('dictionary', dictionary);
})();
How do I append new category object in my dictionary so that it is sorted by category with category objects, e.g.
HTML: [{
category: "HTML",
id: "blog-post",
name: "Blog Post"
}, {...}, {...}],
JavaScript: [{
category: "JavaScript",
id: "curry",
name: "Curry"}, {...}, {...}]