[英]Bracket Notation is Accessing Object With Quotation Marks
我正在使用javascript中的bracket notation
訪問對象。 由於某種原因,它會將值放在引號中...不是我想要的。
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
}
};
如果我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
}
};
這里發生了什么?
我正在從串行端口連接接收action.payload.position
。
字符串的末尾沒有顯示\\r
...使用.trim()
刪除它!
更多信息請參見:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.