代码如下:
将英文名变为中文名
const map = {
id: '编号',
password: '密码',
mobile: '手机号',
username: '姓名',
timeOfEntry: '入职日期',
formOfEmployment: '聘用形式',
correctionTime: '转正日期',
workNumber: '工号',
departmentName: '部门',
staffPhoto: '头像地址'
}
const arr = ['id', 'mobile', 'username']
const change = (map,arr) => arr.reduce((a, b, index) => (a.push(map[arr[index]]), a), [])
const arr2 = change(map, arr)
console.log(arr2) // ['编号', '手机号', '姓名']
这段代码定义了一个对象map,用于将英文字段转换为中文,然后使用数组reduce方法,根据map将数组arr中的英文字段转换为对应的中文名,最后打印转换后的结果。
220

被折叠的 条评论
为什么被折叠?



