I getting data from backend in this format:
{
"id": 1,
"name": "A Great Read",
"slug": "a-great-read",
"image": {
"medium_square_crop": "http://127.0.0.1:6902/media/__sized__/merchants/f4b509269d8ee02501ad01e648a11c72980c782d-crop-c0-5__0-5-400x400-70.jpg",
"full_size": "http://127.0.0.1:6902/media/merchants/f4b509269d8ee02501ad01e648a11c72980c782d.jpg",
"small_square_crop": "http://127.0.0.1:6902/media/__sized__/merchants/f4b509269d8ee02501ad01e648a11c72980c782d-crop-c0-5__0-5-50x50-70.jpg",
"thumbnail": "http://127.0.0.1:6902/media/__sized__/merchants/f4b509269d8ee02501ad01e648a11c72980c782d-thumbnail-100x100-70.jpg"
}
},
{
"id": 2,
"name": "A Place for Everything",
"slug": "a-place-for-everything",
"image": {
"medium_square_crop": "http://127.0.0.1:6902/media/__sized__/merchants/c105bd1ed954c5c465cdd22d04d7009ed4486157-crop-c0-5__0-5-400x400-70.jpg",
"full_size": "http://127.0.0.1:6902/media/merchants/c105bd1ed954c5c465cdd22d04d7009ed4486157.jpg",
"small_square_crop": "http://127.0.0.1:6902/media/__sized__/merchants/c105bd1ed954c5c465cdd22d04d7009ed4486157-crop-c0-5__0-5-50x50-70.jpg",
"thumbnail": "http://127.0.0.1:6902/media/__sized__/merchants/c105bd1ed954c5c465cdd22d04d7009ed4486157-thumbnail-100x100-70.jpg"
}
}
And I have an object created like this:
let obj: { [k: string]: any } = { 'A': [], 'B': [], 'C': [], 'D': [], 'E': [], 'F': [], 'G': [], 'H': [], 'I': [], 'J': [], 'K': [], 'L': [], 'M': [], 'N': [], 'O': [], 'P': [], 'Q': [], 'R': [], 'S': [], 'T': [], 'U': [], 'V': [], 'W': [], 'X': [], 'Y': [], 'Z': [] };
I want to add those names from the API as the value of object keys empty array based on the first letter of the name.
I am fetching data from the backend like this:
ngOnInit():void{
for (let i of this.keys) {
this.api.getMerchantsWithAlbhabet(i).subscribe(x => {
console.log(x.results);
})
}
}