How to iterate/loop over JavaScript Objects
In this post we will give you information about How to iterate/loop over JavaScript Objects. Hear we will give you detail about How to iterate/loop over JavaScript ObjectsAnd how to use it also give you demo for it if it is necessary.
we will learn about different ways through iterate/loop over the JavaScript object.
For in Loop
for in loop helps us to get the object keys by using that keys we are outputting the object values.
This below example shows how to iterate over objects by using a for in loop
const obj = { name: "onlinecode.org", age: 7, location: "web"}for(let key in obj){ console.log(obj.key);}// first iteration obj.name = "onlinecode.org"// second iteration obj.age = 7// third iteration obj.location = "web"Object.keys method
In es6 we can do it a better way by using Object.keys() method.
Object.keys method takes the object as an argument and it returns back the array of keys.
const obj = { name: "onlinecode.org", age: 7, location: "web"}const keys = Object.keys(obj);console.log(keys); // ['name','age','location']for(let key of keys){ console.log(obj.key);}Object.values method
It helps us to get the array of object values instead of object keys.
const obj = { name: "onlinecode.org", age: 7, location: "web"}const values = Object.keys(obj)console.log(values); // ['onlinecode.org',7,'web']for(value of values){ console.log(value);}Output:
'onlinecode.org'7'web'
Hope this code and post will helped you for implement How to iterate/loop over JavaScript Objects. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
How to revoke 'git add' before 'git commit' ?
In this post we will give you information about How to revoke 'git add' before 'git commit' ?. Hear we will give you detail about How to revoke 'git add' before 'git commit' ?And how to use it also give you demo for it if it is necessary.
Sometimes you need to undo your git file before you git comment command. Because you made a some misteck or wrong code and you did git add using "git add ." command then you think how to undo your code before git commit command. But you can do that using git reset command, if you need to undo all file Or you may need to undo just one then you can do using git reset command, you can see bellow command.
Example:
// For Spesific filegit reset
// For all files
git reset
Hope this code and post will helped you for implement How to revoke 'git add' before 'git commit' ?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
