# map简写

# 正常写法

// 课程数据处理
const courseFormat = (item) => {
  return {
    productId: item.id,
    title: item.title,
    coverUrl: item.coverUrl,
    simpleDesc: item.simpleDesc,
    isFree: item.salePrice === 0,
    salePrice: item.salePrice || 0,
    originalPrice: item.originalPrice || 0,
    viewCount: item.studentNum
  }
}

const courseListNew = courseList.map((item) => courseFormat(item))
const courseListFormat = injectRowKey(courseListNew)

courseList.map((item) => courseFormat(item))
如果只有一个item,那么就可以进行简写,如果需要用到index,则不可简写

# 简写

// 课程数据处理
const courseFormat = (item) => {
  return {
    productId: item.id,
    title: item.title,
    coverUrl: item.coverUrl,
    simpleDesc: item.simpleDesc,
    isFree: item.salePrice === 0,
    salePrice: item.salePrice || 0,
    originalPrice: item.originalPrice || 0,
    viewCount: item.studentNum
  }
}

const courseListFormat = injectRowKey(courseList.map(courseFormat))

此为简写方式:
courseList.map(courseFormat)