Just a bit confused as to why the following is occurring:
let groupdetails = {
groupName: "",
};
const groupsArray = [];
groupdetails.groupName = 'A'
groupsArray.push(groupdetails)
groupdetails.groupName = 'B'
groupsArray.push(groupdetails)
console.log(groupsArray)
The result I am getting is:
[ { groupName: "B" }, { "groupName": "B" } ]
The result I was expecting was:
[ { groupName: "A" }, { "groupName": "B" } ]
Unsure what I am doing wrong?