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

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. Commented May 3, 2013 at 8:52

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.