提问者:小点点

未捕获的TypeError:{(中间值)}。映射不是函数[重复]


下面是我的代码:

function employee(rex1){
    const rex = {...rex1}.map((key , value)=>{
        return `${key} : ${value}`


    })
    return `your result is ${rex.join(',')}`
}
console.log(employee({name : 'ahmed' , age : 20})

得到如下错误:

未捕获的TypeError:{(中间值)}。Map不是函数


共1个答案

匿名用户

如果要迭代对象中的键/值对,可以使用object.entries()将它们作为表单中的数组检索

[[key1, val1], [key2, val2], ... [keyn, valn]]

例如

null

function employee(rex1) {
  const rex = Object.entries(rex1).map(([key , value]) => `${key} : ${value}`)

  return `your result is ${rex.join(',')}`
}
console.info(employee({name : 'ahmed' , age : 20}))