我无法映射保存数组的对象属性,因为编译器将其视为字符串类型

问题描述 投票:0回答:1
const add = "add";
const edit = "edit"
const required = {user:[add, edit], profile:[edit]}

for(let p in required){
  console.log(typeof(p))
}


输出:

字符串 字符串

这个 p 类型应该是一个数组,但它显示字符串,为什么?

javascript
1个回答
0
投票

你可以尝试-

const add = "add";
const edit = "edit"
const required = {user:[add, edit], profile:[edit]}

for(let p in required){
  console.log(typeof(required[p]))
}

© www.soinside.com 2019 - 2024. All rights reserved.