convert object to string javascript code example
Example 1: turn object into string javascript
var obj = {a: "a", b: "b" };
var string = JSON.stringify(obj);
Example 2: javascript to string
num.toString();
Example 3: php convert object to array
$person = new stdClass();
$person->firstName = "Taylor";
$person->age = 32;
$personArray = (array) $person;
$personArray = objectToArray($person);
function objectToArray ($object) {
if(!is_object($object) && !is_array($object)){
return $object;
}
return array_map('objectToArray', (array) $object);
}
Example 4: Javascript object to JSON string
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
Example 5: convert array object to string javascript
var ar = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
console.log( ar.join('') );
console.log( ar.join(' : ') );
console.log( ar.join('-') );
console.log( ar.join('|') );
Example 6: cast object to string javascript
var myJSON = JSON.stringify(obj);