简体   繁体   中英

Create a function removeFromPlaylist that accepts two arguments (the playlist object and the artist name)

Create a function removeFromPlaylist that accepts two arguments (the playlist object and the artist name). The body of the function should delete the key-value pair from the playlist and return the updated playlist.

I couldn't past this test with the below code:

function removeFromPlaylist(playlist, artistName) {
  delete playlist.artistName
  return playlist
}

For deletion of the key you have to use the brackets because otherwise it tries to delete "artistName" burt you want to delete the key with the value of artistName.

 function removeFromPlaylist(playlist, artistName) { delete playlist[artistName]; return playlist; } let playlist = { song: 'Hello', artist: "Madonna", duration: "2:34" }; console.log ( removeFromPlaylist( playlist, "artist") );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM