一、字符串

拆分:str.split([separator[, limit]])

截取:

str.slice(beginIndex[, endIndex])

str.substr(start[, length])

str.substring(indexStart[, indexEnd])

替换:str.replace(regexp|substr, newSubStr|function)

查找:

str.includes(searchString[, position])

str.indexOf(searchValue [, fromIndex])

拼接:str.concat(str2, [, ...strN])

去空格:

str.trim()

str.trimEnd();

str.trimRight();

str.trimStart();

str.trimLeft();

二、数组

查找:

arr.indexOf(searchElement[, fromIndex])

arr.find(callback[, thisArg])

arr.findIndex(callback[, thisArg])

arr.includes(valueToFind[fromIndex])

循环、函数式:

arr.forEach(callback(currentValue [, index [, array]])[, thisArg])

var new_array = arr.map(function callback(currentValue[, index[, array]]) {

  // Return element for new_array 

}[, thisArg])

var newArray = arr.filter(callback(element[, index[, array]])[, thisArg])

arr.reduce(callback(accumulator, currentValue[, index[, array]])[, initialValue])

arr.some(callback(element[, index[, array]])[, thisArg])

arr.every(callback(element[, index[, array]])[, thisArg])

删除末尾元素:arr.pop()

删除首个元素:arr.shift()

添加到末尾:arr.push(element1, ..., elementN)

添加到开始:arr.unshift(element1, ..., elementN)

合并数组:var new_array = old_array.concat(value1[, value2[, ...[, valueN]]])

删除/替换:array.splice(start[, deleteCount[, item1[, item2[, ...]]]])

填充:arr.fill(value[start[end]])

扁平化:var newArray = arr.flat([depth])

三、对象

合并:Object.assign(target, ...sources)

键/值:

Object.keys(obj)

Object.values(obj)

冰冻:Object.freeze(obj) 

相关文章:

  • 2022-12-23
  • 2022-01-07
  • 2021-09-14
  • 2022-01-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-04-20
相关资源
相似解决方案