3.5 C
New York
Monday, February 6, 2023

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


var e = "notify-"+items.userid;

io.sockets.emit(e, 1);



Related Articles


Please enter your comment!
Please enter your name here

Latest Articles