We have a simple object with methods
var o = {
fn : (a)=>{}
}
We than add numerical indexed sub objects to it
o[0] = {};
o[1] = {};
So now we have a mixture of methods and numeric properties
o = {
"0" : {}...
"1" : {}...
fn : (a)=>{}
}
This is helpful for various reasons... seems totally legit and possible in JS.
We preferred an object with numeric properties, instead of an array with methods.
The Question : is there a way to get indexOf, splice, various Array.prototype methods to work with this?
We have tried stuff like :
[].indexOf.call(o,_index) // didn't work
...
Is the only solution would be to construct our object as an array, appending methods to it? or maybe there is another way to apply Array.prototype methods on an object?
o[index]and for any array method useobject.keys(), Object.values or Object.entriesand then access key and valuesfnproperty to it.indexOfwould beObject.keys(o).find(k=> o[k] === value). Andsplicewould be to loop fromstarttoendindex anddelete o[index]