//https://www.youtube.com/watch?v=0k4NwimfszA
// json-stringify.js
// Lesser known features when using JSON.stringify()
//Video Tutorial :https://youtu.be/0k4NwimfszA
let obj = {name: "Walter",
last: "Sobchak",
age: 50,
angry: true,
bestscore: 200,
armed: true};
let log = console.log;
let str;
str = JSON.stringify(obj);
log('1', str);
str = JSON.stringify(obj, ['age', 'angry', 'last']);
log('
2', str);
function replace(key, val){
if(typeof val === 'number'){
return undefined;
}else{
return val;
}
}
str = JSON.stringify(obj, replace);
log('
3', str);
str = JSON.stringify(obj, null, 4);
log('
4', str);
str = JSON.stringify(obj, null, ' X X X ');
log('
5', str);