📜  map vs for each - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:25.281000             🧑  作者: Mango

代码示例1
chars = ['Hello' , 'world!!!'] ;
var retVal = chars.forEach(function(word){
  console.log("Saving to db: " + word) 
})
console.log(retVal) //undefined

chars = ['Hello' , 'world!!!'] ;
var lengths = chars.map(function(word){
  return word.length
}) 
console.log(lengths) //[5,8]