Work with wp api and get name by id in ionic


#1

i have music site and in api have artists and songs router : /wp-json/wp/v2/artists /wp-json/wp/v2/songs

in songs - evry songs has artist field that store Song’s artists id

i want by gettings songs the artist’s id of songs convert to artist name

i find this from a tutorial but not work

getArtistName(item.cd_meta.artist[0])

getArtistName(artist_id:number){
let artist_name:string ='';
this.api.Artists.forEach(element =>{
  if (element.id === artist_id){
    artist_name = element.name;
  }
});


  return artist_name;
}

thanks