1.數(shù)組字符串去重
利用es6的set數(shù)據(jù)結(jié)構(gòu)特性:成員的值都是唯一的 來完成數(shù)組去重
數(shù)組去重
let arr = ["1", "2", "3", "2", "5", "1"];
var result =[...new Set(arr)];
console.log(result ); //["1", "2", "3", "5"]
字符串去重
let str = "ababbc";
let result = [...new Set(str)].join("");
console.log(result); //'abc'
2.獲取json的key和value組成的數(shù)組
let json = {
username: "小明",
age: 18,
score: "89",
sex: "男",
};
Object.keys(json); //["username", "age", "score", "sex"]
Object.values(json); //["小明", 18, "89", "男"]