windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server https://softhier.com/ instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

json from mySql databse to object array conversion

Asked By: Anonymous

Im trying to get an object array from my MySql database, however I keep getting the result of "undefined" and I do not know why
my code:

database.query(sql, (err, rows)=>{
    var data = Object.values(JSON.parse(JSON.stringify(rows)))
    console.log(data[0].type)
})

Whenever I console log my "data" variable I get:

[
  {
    data: '[{"type": "c#", "script": "csharp script"}, {"type": "javascript", "script": "javascript script"}, {"type": "html", "script": "html script"}]'
  }
]

which seems correct to me but Im not sure about what to do now.
Any help would be greatly appreciated


Solution

Answered By: Anonymous

The actual data you need is inside the first element’s .data property. It’s a string, so you need to parse it to use as an array of objects.

Working example

_x000D_

_x000D_

let yourData = [{
  data: '[{"type": "c#", "script": "csharp script"}, {"type": "javascript", "script": "javascript script"}, {"type": "html", "script": "html script"}]'
}]

let data = JSON.parse(yourData[0].data)
console.log(data[0].type)

_x000D_

_x000D_

x000D

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno