let awards = ["earth","sun","moon"];
let a = JSON.stringify(awards);
console.log(a);
Result: -["earth","sun","moon"] // no difference?
In my database, text field, I have this:
{"earth","sun","moon"};
update
from this I get php array using:
$arr = json_decode($data['planets'], true);
What is the difference between ["earth","sun","moon"] and {"earth","sun","moon"}
And how to get {"earth","sun","moon"} from js array - ["earth","sun","moon"];?
php, mysqlon server side{"earth","sun","moon"}this is invalid json.{}- encodes object expecting"key": valuepairs. But you have something array-like (comma separated values)let awards = ["earth","sun","moon"]; const str =`{${awards.map(x => JSON.stringify(x))}}`should give the value you want.