How to use foreach object in Nodejs ?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will show you how to use foreach object in NodeJs. Normally, we can use foreach loop in PHP, JS etc, but when we are working on socket programming on that time i must need to use foreach of object in server.js. So here I did also search that on google and i was try to know how to use foreach in Node JS. At last i was found that how use forEach and i can solve it.

so, let’s see the 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);
	});
});

Read Also : How to Add Query String Automatic on Laravel Pagination

Thanks for read. I hope it help you. For more you can follow us onĀ facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →