Is there a way to push an object into a JavaScript array without adding extra keys like 0, 1, 2, etc.? Currently, when I push my object into the array, it automatically adds these numeric keys. Below is the code snippet that I have tried:
let newArr = [];
let myId = data['id'];
var key = myId;
var obj = {};
myobj[key] = {
data: "testdata"
};
newArr.push(myobj);
When I run the above code, the output includes these unwanted numeric keys like 0. How can I achieve pushing the object without those keys?
0: {
260: {
data: 'testdata'
},
}