i new in javascript + nodejs
i want display array in javascript from nodejs..
this result from node.js (i use JSON.stringify())
[{"id":"i01","name":"jack","phone":"123123"},{"id":"i02","name":"john","phone":"123123"},{"id":"i03","name":"jane","phone":"123123"}]
i want display that array like this
id | name | phone
---+-------+----------i01 | jack |123123
i02 | john |123123
i03 | jane |123123
how can i achive what i want ?
thanks
i new in javascript + nodejs
i want display array in javascript from nodejs..
this result from node.js (i use JSON.stringify())
[{"id":"i01","name":"jack","phone":"123123"},{"id":"i02","name":"john","phone":"123123"},{"id":"i03","name":"jane","phone":"123123"}]
i want display that array like this
id | name | phone
---+-------+----------i01 | jack |123123
i02 | john |123123
i03 | jane |123123
how can i achive what i want ?
thanks
Share Improve this question asked May 3, 2013 at 8:41 ltvieltvie 9734 gold badges21 silver badges49 bronze badges 1- It really isn't difficult enough that you need to ask a question on StackOverflow. Just loop through the array and print each of the attributes of each object in the array. – Munim Commented May 3, 2013 at 8:52
2 Answers
Reset to default 1var mypost = [{"id":"i01","name":"jack","phone":"123123"},{"id":"i02","name":"john","phone":"123123"},{"id":"i03","name":"jane","phone":"123123"}]
var mm = mypost[0].id // return i01
var mm1 = mypost[1].name // return john
var mm2 = mypost[2].phone // return 123123(phone3)
take a look here to check the way to iterate an array: For-each over an array in JavaScript?
Hope it helps
Refer below example and apply. Try it once...
var obj = { x: '1', a: '2', b: '3'};
var items = Object.keys(obj);
items.forEach(function(item) {
console.log(item + '=' + obj[item]);
});
its't that much difficult to solve, understand the array concept and iterate concept and apply.
Refer below link for reference of node.js document
http://nodejs/api/buffer.html