freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../functional-programming/use-the-map-method-to-extra.../index.md

1.1 KiB
Raw Blame History

title localeTitle
Use the map Method to Extract Data from an Array 使用映射方法从数组中提取数据

使用映射方法从数组中提取数据

:speech_balloon:提示1

array.prototype.map采用输入中的函数并返回一个数组。返回的数组包含由函数处理的元素。此函数将各个元素作为输入。

扰流警报!

警告牌

提前解决!

:rotating_light:中级代码解决方案:

  rating = watchList.map( (item) => ({"title":item["Title"], "rating":item["imdbRating"]}) ); 

###代码说明: 使用ES6表示法处理数组中的每个项目以提取标题和评级。 返回对象需要Parantheses。

相关链接