0

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

ltvie
  • 931
  • 4
  • 19
  • 48
  • 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 May 03 '13 at 08:52

2 Answers2

1
var 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

Community
  • 1
  • 1
jmingov
  • 13,553
  • 2
  • 34
  • 37
0

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.org/api/buffer.html

Hariharan
  • 3,191
  • 4
  • 19
  • 31