javascript 从nodejs显示数组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16354745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
display array from nodejs?
提问by ltvie
i new in javascript + nodejs
我是 javascript + nodejs 新手
i want display array in javascript from nodejs..
我想在来自 nodejs 的 javascript 中显示数组..
this result from node.js (i use JSON.stringify())
这个结果来自 node.js(我使用 JSON.stringify())
[{"id":"i01","name":"Hyman","phone":"123123"},{"id":"i02","name":"john","phone":"123123"},{"id":"i03","name":"jane","phone":"123123"}]
[{"id":"i01","name":"Hyman","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 | Hyman |123123
i02 | john |123123
i03 | jane |123123
身 | 姓名 | 电话
---+-------+------------i01 | Hyman |123123
i02 | 约翰 |123123
i03 | 简|123123
how can i achive what i want ?
我怎样才能达到我想要的?
thanks
谢谢
回答by jmingov
var mypost = [{"id":"i01","name":"Hyman","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?
看看这里检查迭代数组的方法:在 JavaScript 中的数组上的每个?
Hope it helps
希望能帮助到你
回答by Hariharan
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
请参阅以下链接以获取 node.js 文档的参考