[英]NodeJS: Getting the values from the result of a multiple statement MySQL query
我正在使用 Node.js 中的多語句查詢從數據庫中獲取數據。
我的查詢結果如下:
[ [ RowDataPacket {
name: 'Jericho',
country: 'Canada',
sex: 'Male',
age: 12 } ],
[ RowDataPacket {
interpretation: 'a complex situation' } ],
[ RowDataPacket {
team: 'The Horses',
colour: 'Purple' } ],
[ RowDataPacket {
start_day: 'Monday',
end_day: 'Friday' } ] ]
我試圖從第四個RowDataPacket
中獲取start_day
和end_day
值,以便我可以用破折號加入它們(例如周一至周五)。 我有以下代碼:
var days = rows[3]; //rows is the result of the query
console.log(days.start_day);
console.log(days.end_day);
但是 console.log() 的結果如下:
undefined
undefined
我不確定為什么start_day
和end_day
值被打印為undefined
。 任何見解都值得贊賞。
RowDataPacket 是構造函數 function,它創建了一個 object,看起來像this new RowDataPacket(start_day, end_day)
您可以使用 [0], 0th index 訪問它
var days = rows[3];
console.log(days[0].start_day);
console.log(days[0].end_day);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.