How to use foreach object in NodeJS ?




How to use foreach object in NodeJS ?

How to use foreach object in NodeJS ?

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.

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

 


Author Biography.

Lokesh Gupta
Lokesh Gupta

Overall 3+ years of experience as a Full Stack Developer with a demonstrated history of working in the information technology and services industry. I enjoy solving complex problems within budget and deadlines putting my skills on PHP, MySQL, Python, Codeigniter, Yii2, Laravel, AngularJS, ReactJS, NodeJS to best use. Through Knowledge of UML & visual modeling, application architecture design & business process modeling. Successfully delivered various projects, based on different technologies across the globe.



News & Blogs

06df58ced4c8c6bd7e387d3cd0d4167f.png

Top React.js tools for Developers

React continues to grow in popularity by almost 150% from 2017 to 2018. This ...

04dd32c0108d23bf51249aeab490ad84.png

Get a head start with trending Nodejs developer...

To build and run applications, you need different types of runtime environments that help in seve...

99c65279a4f62ad85fb5b8b340077bb3.png

How to Integrate Payumoney Payment Gateway in L...

I am going to explain How to Integrate Payumoney Payment Gateway in Laravel 5. Most of thing are ...