JS進階程式設計3

來源:互聯網
上載者:User

標籤:play   none   round   定義資料   author   logs   es6   class   key   

PS:有一小部分寫在了 JS 2017了

JSON

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title></title></head><body>IE8支援 JSON.stringify()<script>  var book = {    "title":"js",    "author":"kang",    "edition":3  }  // 1.過濾結果  var res =JSON.stringify(book,[‘title‘,‘author‘])  console.log(res);  console.log(JSON.parse(res).title);  // 2 自訂資料  var res2=JSON.stringify(book,function (key, val) {    switch (key){      case "title":        return val+ ‘ es6‘      case "author":        return ‘jia‘      case "edition":        return undefined      default:        return val    }  })  console.log(res2);  // 3 格式化  var res3=JSON.stringify(book,[‘title‘],2)  // 第3個值是格式化屬性,可以為數字,代碼縮排的空格數,如果是字串,則是用字串代替空格來縮排  // var res3=JSON.stringify(book,[‘title‘],‘---‘)  console.log(res3);  // 4 toJSON   不實用  var book2 = {    "title":"es5 es6",    "year":2017,    toJSON:function () {      return this.title    }  }  console.log(book2.toJSON());  // es5 es6</script></body></html>
View Code

 

JS進階程式設計3

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.