Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JSON stringify method - the optional parameters

//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);
Comment

PREVIOUS NEXT
Code Example
Javascript :: Moralis Password reset web3 
Javascript :: apostrophe issue in javascript 
Javascript :: How display console log in frontend 
Javascript :: cpprestsdk json 
Javascript :: jasmine configrations 
Javascript :: how to route with credentials react 
Javascript :: how to get author in wordpress api react 
Javascript :: how to produce null in accessing array function in javascript 
Javascript :: load mulitple elements in route v6 
Javascript :: execute shell command from html button node js 
Javascript :: js to es6 convertor 
Javascript :: get index from for in loop javascript 
Javascript :: will stop the loop if the array has any negative number and return all the positive numbers before the negative numbers 
Javascript :: resource loads fastest 
Javascript :: js wrap a function pass parameters to function 
Javascript :: nodejs post req accept form data 
Javascript :: twitter user profile regex javascript 
Javascript :: convert json to .env node 
Javascript :: javascript function template 
Javascript :: dynamically create html table in javascript 
Javascript :: Adding Notices in the Block Editor Wordpress 
Javascript :: architecture express.js 
Javascript :: Storing Values With Assignment Operators 
Javascript :: react native red circle bubble 
Javascript :: react hooks remove item from array 
Javascript :: force dom render 
Javascript :: JS check the type stored in the name variable in JS 
Javascript :: success and failure callback functions js 
Javascript :: how concatenate arrays in es6 
Javascript :: mutiple if in express handlebars 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =