-1

I am using mysql on node.js to get an id from some table .And now i wants to store that id in variable.

con.query("SELECT user_id FROM owners where id =?", [ownerId] , function (err, result, fields) {
    let id=result;
    console.log(id);
    if(err) throw err;
    //console.log(result);
    res.send(result);
});

I works perfectly and gets data from server but it stores th value in id is like [ RowDataPacket { user_id: 1642 } ]. But i want my id as only "1642" so that i can use some conditions. Kindl help

1 Answers1

0

You can try for the following:

var parsedResult = JSON.parse(JSON.stringify(result));
let id = parsedResult[0].user_id; 
Subburaj
  • 5,114
  • 10
  • 44
  • 87