I have create one object and that object I need to pass in one method where I need to iterate by using each object. Since my Obj having only values so it its not getting passed. Can any one help me into this.
My Code :
var MyObj = {
country : "Aus",
Time : "EST",
Val : "Pecific"
}
Now this MyObj I need to pass in one method:
this.someMethod(id, MyObj);
In someMethod i Have one code like
Ext.Array.forEach(MyObj, function (Value) {})
At this point it is getting failed because MyObj
is not an array of object. How to correct it.
It would be very helpful if you'd provide more information.
I am not sure what you want to achieve, but there are several ways to iterate through objects.
If you want to split up your object into multiple single-key objects:
> Object.keys(MyObj).map(key => ({ [key]: MyObj[key] }))
[ { country: 'Aus' }, { Time: 'EST' }, { Val: 'Pecific' } ]
On the other hand, if you have a function that takes an array but you want to pass just this one object:
Ext.Array.forEach([MyObj], Value => ())
(But in this case you are better off just calling the function.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With