我遇到了一个问题,正如标题本身所说的那样。
我可以访问数组的特定位置,但无法访问此数组中的特定对象。
export const getAccessLevel = id =>{
const accessLevels = [
{id: 0, name: 'Admin'},
{id: 1, name: 'Customer'},
{id: 2, name: 'Client'},
{id: 3, name: 'Viewer'}
]
let index = accessLevels.findIndex(array => array.id === id);
console.log(index) // result : 3
console.log(accessLevels[index])
// this is returning {id: 3, name: "Viewer"}
let AccessLevelName = accessLevels[index].name
// this is return error : Cannot read property 'name' of undefined
return AccessLevelName
}
撒科打诨
交互式爱情
相关分类