简体   繁体   English

创建一个 function removeFromPlaylist 接受两个 arguments(播放列表 object 和艺术家姓名)

[英]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.

相关问题 JavaScript:创建一个函数defineFirstArg,它接受一个函数和一个参数; 接受更多参数 - JavaScript: Create a function defineFirstArg that accepts a function and an argument; Accept More Arguments JS - 创建一个回调函数,该函数接受调用它的函数返回的对象 - JS - Create a callback function that accepts an object returned by the function invoking it JavaScript:创建一个接受数组和回调的函数groupBy,并返回一个对象 - JavaScript: Create a function groupBy that accepts an array and a callback, and returns an object 如何创建一个接受多个参数的函数以在 JavaScript 中执行算术计算? - How do I create a function that accepts multiple arguments to perform an arithmetic calculation in JavaScript? 创建接受对象类型为 arguments 的通用接口 - Create generic interface that accepts type of objects as arguments “创建播放列表”,Spotify Web API返回201,但没有播放列表对象 - “Create a Playlist” with Spotify Web API returning 201 but without a playlist object 接受以下内容的函数:字符串或函数或两个对象 - A function that accepts: a string or a function or two objects 创建播放列表 - Create Playlist 动态创建一个按钮,并设置“ onclick”处理程序并接受多个参数 - Create a button dynamically and set “onclick” handler with accepts multiple arguments 为createElement创建函数,该函数接受更多参数 - Create function for createElement that accepts more parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM