How to use foreach object in Nodejs ?

By Hardik Savani | March 31, 2016 | | 53256 Viewer | Category : PHP Laravel Node JS


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);

});

});



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.