当前位置: 首页 > Web前端 > HTML5

es5_JSON

时间:2023-04-05 10:50:45 HTML5

es5_JSONletstr='[{"name":"大胖","age":23},{"name":"小胖","age":24}]';letarr=[{"name":"大胖子","age":23},{"name":"小胖","age":24}];用于将json字符串转换为json对象(json反序列化):letjsonObj=JSON.parse(str);console.log(jsonObj);//打印出[Object,Object]将json对象转成json字符串(json序列化):letjsonStr=JSON.stringify(arr);console.log(jsonStr);//打印出来[{"name":"大胖","age":23},{"name":"骚胖","age":24}]Stringtrim:letstr5='abc';console.log("|"+str5+"|");//打印出来|美国广播公司|console.log("|"+str5.trim()+"|"??);//打印输出|abc|regularity:letreg=/^(\s+)|(\s+)$/g;console.log("|"+str5.replace(reg,'')+"|"??);//打印输出|abc|Date:console.log(Date.now());//打印出1500706861909console.log(newDate().toJSON());//打印出2017-07-22T07:01:01.909Zconsole.log(newDate().toISOString().slice(0,10));//打印出2017-07-22Number:leta=newNumber(1.326);让b=新数字(1.324);console.log(a.toFixed(2));//打印出1.33console.log(b.toFixed(2));//打印出1.32letc=10000000000000;console.log(c.toPrecision(4));//打印出1.000e+13console.log(Math.round(12.34));//打印出12函数调用apply:varx=1;让obj5={x:2}functionfn1(a,b){console.log(this.x);}fn1();让fn2=fn1.bind(obj5);fn2();