I have a problem with a javascript (i'm a noob) so i can't figure out a solution. Actually i have a json file, i can achieve to get the results i need, but are not grouped, and i can 't find a way for group them. What i would achieve is to have all the albums of userid1 in a group and so on. I tried using Groupby, but seems not working. May can you help me? That's the code.
Thanks for help
EDIT: There's a second Json called photos... so i tried to merge them in order to have just one json file...but i think i miss something because seems to not work
async function getAlbums() {
let url = 'https://jsonplaceholder.typicode.com/albums';
try {
let res = await fetch(url);
return await res.json();
} catch (error) {
console.log(error);
}
}
async function getPhotos() {
let url = 'https://jsonplaceholder.typicode.com/photos';
try {
let res1 = await fetch(url);
return await res1.json();
} catch (error) {
console.log(error);
}
}
async function renderAlbums() {
let albums = await getAlbums();
let html = '';
albums.forEach(albums => {
let htmlSegment = `<div class="albums">
<h2>ALBUM MADE BY USER
${albums.userId} </h2>
<h2>ALBUM NAME: ${albums.title}</h2>
<div class="photos">
</div>`;
html += htmlSegment;
});
let container = document.querySelector('.container');
container.innerHTML = html;
}
renderAlbums();