GH1995 / articles

blog
https://gh1995.github.io
2 stars 0 forks source link

javascript[3] #48

Open GH1995 opened 4 years ago

GH1995 commented 4 years ago
/**
 * Date
 */
var now = new Date();
now.getFullYear(); //=
now.toLocaleString(); //=

/**
 * RegExp
 */
var re = /^\d{3}\-\d{3,8}$/;
re.test("010-12345"); //=

// @切分字符串
"a b   c".split(/\s+/); //=

// @提取子串
var re = /^(\d{3})-(\d{3,8})$/;
re.exec("010-12345")[1]; //=

/**
 * JSON
 */

// @序列化
var xiaoming = {
  name: "小明",
  age: 14,
  gender: true,
  height: 1.65,
  grade: null,
  "middle-school": '"W3C" Middle School',
  skills: ["JavaScript", "Java", "Python", "Lisp"]
};
var s = JSON.stringify(xiaoming); //=

// @反序列化
JSON.parse(s); //=