当前位置:网站首页>JS built-in method
JS built-in method
2022-07-24 08:41:00 【zhougl996】
Js String method
filter() Filtration method
If the return value is true, keep this value
// Filtration is greater than 0
jsString = jsString.filter(item => {
return item > 0
});
// Find the city of Shandong
jsString = jsString.filter(item => {
return item.city === ' Shandong '
});
unshift(param)
Its parameters will be inserted arrayObject The head of
var arr = new Array()
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr + "<br />")
document.write(arr.unshift("William") + "<br />")
document.write(arr)
sort()
Sort
// If you sort in ascending order
Array.sort(function(a, b) {
return a - b
})
// If sorted in descending order
Array.sort(function(a, b) {
return b - a
})
// according to key sorted
Array.sort(function(obj1, obj2) {
let val1 = obj1.key
let val2 = obj2.key
return val1 - val2
})Convert characters to numeric arrays
a="1,2,3,4,5" // ''.split(',') Returns the [""], Then .map[Number] Returns the [0]
if (a == '') {
b=[]
} else {
b=a.split(",") // ["1", "2", "3", "4", "5"]
b.map(Number) // [1, 2, 3, 4, 5]
}
JavaScript Array includes() Method
let site = ['runoob', 'google', 'taobao'];
site.includes('runoob');
// true
site.includes('baidu');
// false
[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false
[1, 2, 3].includes(3, 3); // false
[1, 2, 3].includes(3, -1); // true
[1, 2, NaN].includes(NaN); // trueOf an object in an array key Objects with equal values are combined into one object , loop Map
// take id Merge the same
let chartDatas = this.groupBy(results, item => item.id);
groupBy(array, f) {
// initialization Map, Used to store key value pairs
let map = new Map();
array.forEach(function(obj) {
// According to the function passed in , Generate a for each object in the array key value , And will key Objects with equal values are grouped
let key = f(obj);
map.set(key, (map.get(key) || []));
map.get(key).push(obj);
});
return map;
},
for (var [key, value] of chartDatas) {
let k = key;
let v = value;
console.log('key: ' + k + ' value: ' + v);
}边栏推荐
- 2022.7.11 overall solution
- [technical interview] how to introduce yourself
- Xiaobai learns oauth2
- Beandefinition three ways to load beans
- MySQL date formatting
- 「题解」蝙蝠侠的麻烦
- Relationship between fork and pipeline
- 4、 Midway integrates swagger and supports JWT bearers
- Hack the box - Introduction to networking module detailed Chinese tutorial
- 3、 Midway interface security certification
猜你喜欢

基于FPGA的VGA字符显示

Route interceptor

Encryption market ushers in a new historical cycle. Look at jpex's "stability" and "health"

Overseas media, domestic we media, media publicity

Shanghai issued a document to support the entry of NFT cultural exchange: the trend of digital collections has arrived!
![[wechat applet development (III)] realize the stacking and sliding of cards](/img/6c/4ebd60a2106b56b8bf3a6bf17d11f9.png)
[wechat applet development (III)] realize the stacking and sliding of cards

【FFH】实时聊天室之WebSocket实战

Porting boa server on imx6ull

Introduction to wechat authorized login third-party app applet method

Cyclic multiple scatter
随机推荐
G1 (garbage first) collector
Recursive performance test
Porting boa server on imx6ull
JQ native write bullet frame mask layer
Look at the most influential infrastructure m-dao of Web3 through the current situation of Dao
MySQL日期格式化
Summary of points management system project
Enterprises love hybrid app development, and applet container technology can improve efficiency by 100%
[wechat applet development (II)] custom navigation bar
Confusing defer, return, named return value, anonymous return value in golang
Take out the string in brackets
看了纪录片《埃达克岛的海盗宝藏》,想到我国历史上的遗失秘宝
Typescript decorator
情人节
Kotlin learning note 1 - variables, functions
"Explanation" change exchange
T-SQL query statement
Rk3566 add project under external
Wei Xiaoli's "pursuer" is coming
How difficult is it to build a digital collection platform?