Storing a javascript array that contains objects in a MYSQL database?
somehow making it a string and then saving it as text, but I don't really know a very efficient and "smart" way to do that.
Save the string as JSON, like this:
var myArr = [{x1:0,x2:2000,y:300},{x1:50,x2:250,y:500}];myArrString = JSON.stringify(myArr);
Later, when you get the JSON string back from MySQL, you can turn it back into an array with JSON.parse()
, like this:
var myArr = JSON.parse(myArrString)
And yes, if you're wondering, JSON functionality has been added to Javascript's standard codebase: that's how popular it is.