I want to post a variable through AJAX.
The typeof variable is "object".
If I directly post an object, the AJAX fails. I used JSON.stringify but then it’s in ["10","11","12"] format.
I need a string similar to 10,11,12. How do I do that?
The String() function converts the value of an object to a string. The String() function returns the same value as toString() of the individual objects.
function myFunction() {
var x1 = ["10","11","12"];
var res = String(x1) + "<br>";
document.getElementById("demo").innerHTML = res;
}
<p>Click the button to convert object to string.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
Array.prototype.join. If it is an object, then is it keys or values or what? Show some code.