Why does the first console display the value after operating map?

let dataSource=[
      {
        id: "0",
        userName: "Jack",
        sex: "1",
        state: "1",
        interest: "1",
        birthday: "2018-1-1",
        address: "",
        time:"19:35",
      },
      {
        id: "1",
        userName: "daoma",
        sex: "1",
        state: "1",
        interest: "1",
        birthday: "2018-1-1",
        address: "",
        time:"19:35",
      },
      {
        id: "2",
        userName: "wawa",
        sex: "1",
        state: "1",
        interest: "1",
        birthday: "2018-1-1",
        address: "",
        time:"19:35",
      },
    ]
    console.log("1",dataSource)
    dataSource.map((item,index)=>{
      item.key = index
    })
    console.log("2",dataSource)

result:

Apr.24,2021

because when you click on the developer tool object model, the developer tool dynamically updates the value at this time! See that small I sign, mouse up to see its prompt text.

clipboard.png

you can write the first console as console.log ('1recording console.log DataSource [0] .key); , you'll see right away: the output is undefined, as we expected.

Menu