资讯专栏INFORMATION COLUMN

es5_JSON

paulquei / 2573人阅读

摘要:大胖骚胖大胖骚胖用来将字符串转成对象的反序列化打印出用来将对象转成字符串的序列化打印出大胖骚胖打印出打印出正则打印出打印出打印出打印出打印出打印出打印出打印出

es5_JSON

</>复制代码

  1. let str = "[{"name":"大胖","age":23},{"name":"骚胖","age":24}]";
  2. let arr = [
  3. {"name":"大胖","age":23},
  4. {"name":"骚胖","age":24}
  5. ];

用来将json字符串转成json对象(json的反序列化):

</>复制代码

  1. let jsonObj = JSON.parse(str);
  2. console.log(jsonObj);//打印出[Object, Object]

用来将json对象转成json字符串(json的序列化):

</>复制代码

  1. let jsonStr = JSON.stringify(arr);
  2. console.log(jsonStr);//打印出[{"name":"大胖","age":23},{"name":"骚胖","age":24}]

String trim:

</>复制代码

  1. let str5 = " abc";
  2. console.log("|"+str5+"|");//打印出| abc|
  3. console.log("|"+str5.trim()+"|");//打印出|abc|

正则:

</>复制代码

  1. let reg = /^(s+)|(s+)$/g;
  2. console.log("|"+str5.replace(reg,"")+"|");//打印出|abc|

Date:

</>复制代码

  1. console.log(Date.now());//打印出1500706861909
  2. console.log(new Date().toJSON());//打印出2017-07-22T07:01:01.909Z
  3. console.log(new Date().toISOString().slice(0,10));//打印出2017-07-22

Number:

</>复制代码

  1. let a = new Number(1.326);
  2. let b = new Number(1.324);
  3. console.log(a.toFixed(2));//打印出1.33
  4. console.log(b.toFixed(2));//打印出1.32
  5. let c = 10000000000000;
  6. console.log(c.toPrecision(4));//打印出1.000e+13
  7. console.log(Math.round(12.34));//打印出12

function call apply:

</>复制代码

  1. var x = 1;
  2. let obj5 = {
  3. x:2
  4. }
  5. function fn1(a,b){
  6. console.log(this.x);
  7. }
  8. fn1();
  9. let fn2 = fn1.bind(obj5);
  10. fn2();

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/84237.html

相关文章

发表评论

0条评论

paulquei

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<