How to use foreach object in Nodejs ?
In this post we will give you information about How to use foreach object in Nodejs ?. Hear we will give you detail about How to use foreach object in Nodejs ?And how to use it also give you demo for it if it is necessary.
Normally, we does use foreach loop in PHP, JS etc, but when i was working on socket programming at that time i require to use foreach of object in server.js. I did also search on google and try to how to use foreach in Node JS. At last i found to use forEach and solve it. so, let’s see following example.
Example
socket.on("newmessage", function(obj) {
obj = JSON.parse(obj);
obj.forEach(function(items) {
console.log(items.userid);
var e = "notify-"+items.userid;
io.sockets.emit(e, 1);
});
});
Hope this code and post will helped you for implement How to use foreach object in Nodejs ?. 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