【发布时间】:2018-06-09 05:44:38
【问题描述】:
我想转换对象 watchList 数组中给出的 imdb 评级。我正在尝试使用地图功能,但它没有发生。 newList 只给出旧列表,没有任何变化。我做错了什么?
var watchList = [
{
"Metascore": "74",
"imdbRating": "8.8",
"imdbVotes": "1,446,708",
"imdbID": "tt1375666",
"Type": "movie",
"Response": "True"
},
{
"Metascore": "74",
"imdbRating": "8.6",
"imdbVotes": "910,366",
"imdbID": "tt0816692",
"Type": "movie",
"Response": "True"
},
{
"Metascore": "82",
"imdbRating": "9.0",
"imdbVotes": "1,652,832",
"imdbID": "tt0468569",
"Type": "movie",
"Response": "True"
}
];
let newList=[];
newList=watchList.map(function(list){
Number(list.imdbRating);
return list;
});
console.log(newList);
【问题讨论】:
-
Number(list.imdbRating);创建一个数字...然后您忽略结果 -
试试
list.imdbRating = Number(list.imdbRating);
标签: javascript function dictionary reduce