+ 1
For of loops for window object in js is not iterable .explain please.
I have used for... of loop on string it works But when I applied it on window object it console an error that window object is not iterable. How both the objects are different ?? As we know string is also an object in js.
11 odpowiedzi
+ 3
You should use the for/in loop to iterate over the window object. If you want the value of the window properties, use the computed property ex. window[prop].
https://code.sololearn.com/WVwWpz69ll8Z/#js
+ 4
Can you show your code please.
+ 4
Try now may be this will be work replace your line 16
var myobjt = Object.create(window) ;
for(var key in myobjt){
console.log(key);
+ 4
+ 2
Strings are not objects, they are primitive type but strings, as do most of the other primitives, have wrappers objects that allow the primitives to be access and manipulated in some form or fashion.
references-
https://developer.mozilla.org/en-US/docs/Glossary/Primitive
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
0
Sorry I forgot to share it
https://code.sololearn.com/WfyuYDPUNHn8/?ref=app
0
But I want to get value of object not key
Hence I am using for of loop
0
But I want the value from window object not from myarray array.
0
🗡️ Ulduz 🗡️
using
For in loop we can only get the key of object not value of object.
Try for in and for of in case of string both are not same.in case of string key is index and value is character.
Similarly I want to get key and value for window object.
0
It works for singelton object better
0
I have just read every data in js is an object .
But now I think it is more right to say everything in js act like object.
Or hey ODLNT am I still wrong??
Please answer if you aren't agree with this above statement.