One of attribute lost data when assign javascript object

Viewed 32

I spend a day for investigating this case, but seen no hope.

const Tests = (state = INIT_STATE, action) => {
  switch (action.type) {
    case GET_TEST_DETAIL:
      return {
          ...state,
          test: {},
          error: {},
          updatingTest: true,
      }

    case GET_TEST_DETAIL_SUCCESS:
      const test = action.payload
      console.log(action.payload.shortName)//has data
      test["shortName2"] = action.payload.shortName//has data
      test["shortName"] = action.payload.shortName//empty string

      console.log(test)

      return {
          ...state,
          test: test,
          updatingTest: false,
      }

There is the picture captured when I console.log in firefox, and Edge: enter image description here

1 Answers

There's nothing wrong.

const action  = {
  payload: {
    shortName: 'I am a shortname'
  }
}

      const test = action.payload
      console.log(action.payload.shortName)//has data
      test["shortName2"] = action.payload.shortName//has data
      test["shortName"] = action.payload.shortName//empty string

      console.log(test)

Related