Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 括号表示法使用引号访问对象_Javascript_Object_Redux - Fatal编程技术网

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,

我在javascript中使用括号符号访问对象。出于某种原因,它将值加上引号。。。不是我想要的

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
    }
  };
如果I
console.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感谢您的回复。最后弄明白了:)很快就会发布答案