字符串
Reflect.ownKeys(String.prototype)
// 部分不重要的做了删减
[
"anchor",
"at",
"big",
"blink",
"bold",
"charAt",
"charCodeAt",
"codePointAt",
"concat",
"endsWith",
"fontcolor",
"fontsize",
"fixed",
"includes",
"indexOf",
"italics",
"lastIndexOf",
"link",
"localeCompare",
"match",
"matchAll",
"normalize",
"padEnd",
"padStart",
"repeat",
"replace",
"replaceAll",
"search",
"slice",
"small",
"split",
"strike",
"sub",
"substr",
"substring",
"sup",
"startsWith",
"toString",
"trim",
"trimStart",
"trimLeft",
"trimEnd",
"trimRight",
"toLocaleLowerCase",
"toLocaleUpperCase",
"toLowerCase",
"toUpperCase",
"valueOf"
]
var str = 'helloworld45zanlan'
console.log(str.endsWith('zanlan'));// true
console.log(str.startsWith('helloworld')); // true
console.log(str.includes('45')); // true
console.log('zanlan-'.repeat(3));// 'zanlan-zanlan-zanlan-'
console.log(/hell/.test(str)) // true
console.log(str.length)//18
'aAcd'.charCode.At(1) // 65
'aAcd'.charCode.At(0) // 97
String.fromCharCode(65)// "A"
String.fromCharCode(97)// "a"
'aAcd'.toLowerCase() // 'aacd'
'aAcd'.toUpperCase() // 'AACD'
'123456789'.substr(1,3) // "234" 截取长度为3
'123456789'.substring(1,3) // "23"
'123456789'.slice(1,3) // '23'
'123456789'.slice(-3,-1) // '78'
'123456789'.slice(-3) // '789'
'123456789'.substr(-3) // '789'
'123456789'.slice(30) // ''
'123456789'.substr(30) // ''
var str = "The full name of China is the People's Republic of China.";
console.log(str.indexOf("China")) // 17
console.log(str.indexOf("China",18)) // 51 18 ~ 终止位置56, 范围内找
console.log(str.lastIndexOf("China")) // 51
console.log(str.lastIndexOf("China"),50) // 17 50 ~ 起始位置0 范围内找
console.log(str.indexOf("America")) // -1
console.log(str.lastIndexOf("America")) // -1
console.log(str.search("China")) // 17 和indexOf功能一样,但是不能设置第二个参数
console.log(str.replace('is','yes')) // "The full name of China yes the People's Republic of China.";
console.log(str.replace(/china/gi,'China-China')) // The full name of China-China is the People's Republic of China-China.;
" Hello World! ";
console.log(" Hello World! ".trim())
var str = "HELLO WORLD";
str[0] = "A"; // 只读的,不产生错误,但不会工作
console.log(str[0])// 返回 H
console.log(str[30]) // undefined
console.log(str.charAt(30)) // ""
数组
Reflect.ownKeys(Array.prototype)
[
"length",
"constructor",
"at",
"concat",
"copyWithin",
"fill",
"find",
"findIndex",
"lastIndexOf",
"pop",
"push",
"reverse",
"shift",
"unshift",
"slice",
"sort",
"splice",
"includes",
"indexOf",
"join",
"keys",
"entries",
"values",
"forEach",
"filter",
"flat",
"flatMap",
"map",
"every",
"some",
"reduce",
"reduceRight",
"toLocaleString",
"toString",
"findLast",
"findLastIndex",
null,
null
]
对象
Reflect.ownKeys(Object.prototype)
[
"constructor",
"__defineGetter__",
"__defineSetter__",
"hasOwnProperty",
"__lookupGetter__",
"__lookupSetter__",
"isPrototypeOf",
"propertyIsEnumerable",
"toString",
"valueOf",
"__proto__",
"toLocaleString"
]
函数
Reflect.ownKeys(Function.prototype)
[
"length",
"name",
"arguments",
"caller",
"constructor",
"apply",
"bind",
"call",
"toString",
null
]
统计字符串出现的次数,按权重排序
字符统计
var brr = "aaddccdc".split("");
var map = new Map();
brr.forEach((item) => {
map.set(item, (map.get(item) || 0) + 1);
});
var arr = Array.from(map)
arr.sort(function (a, b) {
if (a[1] - b[1] == 0) {
return a[0].charCodeAt(0) - b[0].charCodeAt(0)
}
return b[1] - a[1]
})
var result = arr.reduce(function (res, item) {
return res += item[0]
}, '')
console.log(result) // "cda"