var arr = [];
arr['k1'] = 100;
console.log(arr); //o/p - [k1: 100]
arr.length; //o/p - 0
window.copy(arr); //copies: []
I want to convert this array-like object to a proper obj i.e,
arr = { k1: 100}
So doing window.copy(arr) should copy {k1:100}
NOTE- I need to do this as Node.js express server returns empty arrays in response for such cases.
arr['k1'] = 100doesn't do what you think it does. It doesn't create an index calledk1with a value of100. It creates an entirely new property on this instance of an Array calledk1and sets the value to100. If you were to loop over the array indexes, you'd never seek1show up and it is why the.lengthis0.