1.基本引用类型
let t1=Date.now();
let t2=new Date(2021,1,3,21,58,0);
console.log(t2.getTime());
console.log(t2.setTime(1612360680000));
console.log(t2.getFullYear());
console.log(t2.setFullYear(2021));
console.log(t2.getMonth());
console.log(t2.setMonth(1));
console.log(t2.getDate());
console.log(t2.setDate(3));
console.log(t2.getDay());
console.log(t2.getHours());
console.log(t2.setHours(21));
console.log(t2.getMinutes());
console.log(t2.setMinutes(58));
console.log(t2.getSeconds());
console.log(t2.setSeconds(0));
console.log(t2.getMilliseconds());
console.log(t2.setMilliseconds(0));
let text="cat, bat, \n sat, fat";
let pattern=/.at/g;
let matches=pattern.exec(text);
console.log(matches.index);
console.log(matches[0]);
console.log(pattern.lastIndex);
matches=pattern.exec(text);
console.log(matches.index);
console.log(matches[0]);
console.log(pattern.lastIndex);
matches=pattern.exec(text);
console.log(matches.index);
console.log(matches[0]);
console.log(pattern.lastIndex);
console.log(pattern.test(text));
let num=50.00001;
console.log(num.toFixed(2));
console.log(num.toExponential(2));
console.log(num.toPrecision(2));
console.log(num.toPrecision(1));
console.log(Number.isInteger(1));
console.log(Number.isInteger(1.00));
console.log(Number.isInteger(1.01));
let message="a😊";
console.log(message.length);
console.log(message.charAt(1));
console.log(message.charAt(2));
console.log(message.charCodeAt(1));
console.log(message.charCodeAt(2));
console.log(message.codePointAt(1));
console.log(message.codePointAt(2));
console.log(String.fromCharCode(55357,56842));
console.log(String.fromCodePoint(55357,56842));
let str="hello world";
console.log(str.concat("!!"));
console.log(str.slice(3,7));
console.log(str.substring(3,7));
console.log(str.substr(3,7));
console.log(str.slice(3,-4));
console.log(str.substring(3,-4));
console.log(str.substr(3,-4));
console.log(str.indexOf("o"));
console.log(str.lastIndexOf("o"));
console.log(str.indexOf("o",6));
console.log(str.lastIndexOf("o",6));
console.log(str.startsWith("hello"));
console.log(str.endsWith("world"));
console.log(str.includes("o w"));
console.log(" hello word ".trim());
console.log("ha ".repeat(3));
console.log('foo'.padStart(6));
console.log('foo'.padEnd(6,'.'));
console.log(str.toLowerCase());
console.log(str.toUpperCase());
let text="cat, bat, sat, fat";
let matches=text.match(/.at/);
console.log(matches.index);
console.log(matches[0]);
console.log(text.search(/at/));
console.log(text.replace(/at/g,"ond"));
console.log(text.replace(/(.at)/g,"word($1)"));
let uri="http://www.wrox.com/illegal value.js#start";
console.log(encodeURI(uri));
console.log(encodeURIComponent(uri));
eval("console.log(uri)");
console.log(Math.max(3,54,32,16));
console.log(Math.min(3,54,32,16));
console.log(Math.ceil(25.1));
console.log(Math.floor(25.9));
console.log(Math.round(25.1));
console.log(Math.round(25.9));
2.集合引用类型
let a=[1,2,3,4];
console.log(Array.from(a,function(x){
return x**this.exponent
},{exponent:2}));
console.log(Array.of(1,2,3,4));
let zeros=[0,0,0,0,0];
console.log(zeros.fill(7,1,4));
console.log(a.copyWithin(1,0,2));
console.log(a.toString());
console.log(a.join('||'));
let colors=[];
colors.push("red","green");
colors.unshift("black","brown");
colors.pop();
colors.shift();
colors.concat(["red","green"]);
colors.splice(2,1,"yellow");
let values=[0,1,5,10,15]
console.log(values.sort());
console.log(values.sort((v1,v2) => v2-v1));
console.log(values.reverse());
let numbers=[1,2,3,4,5,4,3,2,1];
console.log(numbers.indexOf(4));
console.log(numbers.lastIndexOf(4));
console.log(numbers.includes(4));
console.log(numbers.includes(4,7));
const people=[
{
name:"Matt",
age:27
},
{
name:"Nicholas",
age:29
}
]
people.find((element,index,array) =>element.age<28);
people.findIndex((element,index,array) =>element.age<28);
numbers.every((item,index,array) => item>2);
numbers.some((item,index,array) => item>2);
numbers.filter((item,index,array) => item>2);
numbers.map((item,index,array) => item*2);
numbers.forEach((item,index,array) =>{
})
numbers.reduce((prev,cur,index,array) => prev+cur);
numbers.reduceRight((prev,cur,index,array) => prev+cur);
const s=new Set();
s.add("Matt");
s.add("Frisibie");
console.log(s.has("Matt"));
console.log(s.size);
s.delete("firstName");
s.clear();
const m=new Map();
m.set("firstName","Matt");
m.set("lastName","Frisibie");
console.log(m.has("firstName"));
console.log(m.get("firstName"));
console.log(m.size);
m.delete("firstName");
m.clear();
3.迭代器和生成器