[英]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).创建一个 function
removeFromPlaylist
,它接受两个 arguments(播放列表 object 和艺术家姓名)。 The body of the function should delete the key-value pair from the playlist and return the updated playlist. function 的主体应该从播放列表中删除键值对并返回更新的播放列表。
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 delete playlist[artistName];
要删除密钥,您必须使用方括号delete playlist[artistName]; because otherwise it tries to delete "artistName" burt you want to delete the key with the value of artistName.
因为否则它会尝试删除“artistName”,你想删除值为artistName的键。
function removeFromPlaylist(playlist, artistName) { delete playlist[artistName]; return playlist; } let playlist = { song: 'Hello', artist: "Madonna", duration: "2:34" }; console.log ( removeFromPlaylist( playlist, "artist") );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.