Javascript 括号表示法使用引号访问对象
我在javascript中使用括号符号访问对象。出于某种原因,它将值加上引号。。。不是我想要的Javascript 括号表示法使用引号访问对象,javascript,object,redux,Javascript,Object,Redux,我在javascript中使用括号符号访问对象。出于某种原因,它将值加上引号。。。不是我想要的 console.log(positions) { element: null, elementTwo: null, elementThree: null, "elementThree": 1 } 更多信息 我在redux中的reducer中有以下状态 const initialState = { positions: { element: null,
console.log(positions)
{
element: null,
elementTwo: null,
elementThree: null,
"elementThree": 1
}
更多信息
我在redux中的reducer
中有以下状态
const initialState = {
positions: {
element: null,
elementTwo: null,
elementThree: null
}
};
我应该可以很容易地操纵它
case SET_POSITION:
console.log(action.payload.element) //elementTwo
return {
...state,
positions: {
...state.positions,
[action.payload.element]: action.payload.position
}
};
如果Iconsole.log(action.paylod.element)
和console.log('elementThree')
它们是相同的
而且,如果我使用以下方法访问,它将起作用:
case SET_POSITION:
console.log(action.payload.element) //elementTwo
return {
...state,
positions: {
...state.positions,
['elementThree']: action.payload.position
}
};
这里发生了什么?我正在从串行端口连接接收
操作.有效负载.位置
字符串末尾没有显示一个\r
。。。使用.trim()
删除此选项
更多信息请参见:
在完成[action.payload.element]:action.payload.position]之后,您在您的状态中有哪些道具?@Valerii感谢您的回复。最后弄明白了:)很快就会发布答案