stringify array javascript code example
Example 1: how to convert array to string json
var arr = [ "John", "Peter", "Sally", "Jane" ];
var myJSON = JSON.stringify(arr);
Example 2: Javascript object to JSON string
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
Example 3: convert json.stringify to array in javascript
const myObj = {
name: 'Skip',
age: 2,
favoriteFood: 'Steak'
};
const myObjStr = JSON.stringify(myObj);
console.log(myObjStr);
console.log(JSON.parse(myObjStr));
Example 4: 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 5: json.stringify file object return {}
var fileObject = getFile();
var newObject = {
'lastModified' : fileObject.lastModified,
'lastModifiedDate' : fileObject.lastModifiedDate,
'name' : fileObject.name,
'size' : fileObject.size,
'type' : fileObject.type
};
JSON.stringify(newObject);