Abhinav Ch Abhinav Ch - 6 days ago 5x
JSON Question

Printing users details which are in JSON format Like foreach in php

Since I'm new to NodeJS, I dont understand how to print all users and their details fettched from database which is in JSON format.

Like in PHP

foreach($users as $user){
echo $user->user_name;

how to fetch user details one by one like above or any other way if the JSON data fetched from db is shown like below:

data = [{"uid":14,"name":"Sam"},{"uid":17,"name":"Sid"},{"uid":19,"name":"Saz"}];


You can use normal for loop for the above task.

for (var i=0; i<data.length; i++) {

The result will look like

uid: 14 name:Sam
uid: 17 name:Sid
uid: 19 name:Saz