1.1 KiB
1.1 KiB
title | localeTitle |
---|---|
Use the map Method to Extract Data from an Array | 使用映射方法从数组中提取数据 |
使用映射方法从数组中提取数据
提示:1
array.prototype.map采用输入中的函数并返回一个数组。返回的数组包含由函数处理的元素。此函数将各个元素作为输入。
扰流警报!
提前解决!
中级代码解决方案:
rating = watchList.map( (item) => ({"title":item["Title"], "rating":item["imdbRating"]}) );
###代码说明: 使用ES6表示法,处理数组中的每个项目以提取标题和评级。 返回对象需要Parantheses。