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

e58d929bc4999ddd2bd803bd94eb1cac.png

What It Was Like to Write a Full Blown Flutter App

1. Porting an iOS App to Flutter Since my last post about Flutter months ago, I felt that the lo...

f62dbc1a41f2267ac3920998ea272871.jpg

You Don’t Need Loops in JavaScript

1. To Loop Through All Elements and Get an new modified array Using loop: var names = ["Jack",...

ebd1a2ed9fd0a6e8dd70b6097706cea5.jpeg

How to Create a Chatbot Using Dialogflow

Chatbots are artificially intelligent programs by which we can make our websites more interactive...