这是我的代码:
app.get('/index/:name',function(req, res){
data = connection.query('SELECT * FROM deneme', function(err, rows, fields){
if(err) throw err;
veri = rows;
return veri;
});
console.log(data);
res.render('index', {
title: req.params.name,
para: data
});
});
当我调用localhost:8080/index/example
时,它返回[object Object]
我想打印数组的数据,我该怎么做?
当我使用带有 print_r() 函数的 php 时,我可以做到这一点。
同时,数组的数据:
Id Name
1 yab
2 sad
最佳答案
我认为 OP 只是想打印数据以用于调试目的,因为您可以使用以下跨浏览器方式,使用 JSON 来打印数据的良好表示:
console.log( JSON.stringify(data, null, 4) );
关于javascript - 我怎样才能打印数组的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13670733/