V. *_*ang 5 javascript methods
我知道我可以在 MDN 上找到一组 mutator 方法,但实际上我总是忘记 push() 或 reverse() 之类的方法是否会改变原始数组或创建一个新数组。为什么某些方法是变异器而有些是非变异器,所以我很容易记住,这是否有逻辑?
也许记住它们的一种有用方法是识别变异方法并将它们分组;只有少量。
从数组中添加/删除:
Array.prototype.fill() - 在任何地方覆盖元素Array.prototype.pop() - 从头删除Array.prototype.push() - 添加到开头Array.prototype.shift() - 从末端移除Array.prototype.unshift() - 添加到结尾Array.prototype.splice() - 在任何地方添加/删除重新排列数组:
Array.prototype.flat() - 展平一个数组Array.prototype.sort() - 使用排序功能重新排列元素Array.prototype.reverse() - 反向元素古怪:
Array.prototype.copyWithin() - 老实说,我从未使用过这种方法变异数组方法列表 -
Array.prototype.copyWithin()Array.prototype.fill()Array.prototype.flat()Array.prototype.pop()Array.prototype.push()Array.prototype.reverse()Array.prototype.shift()Array.prototype.sort()Array.prototype.splice()Array.prototype.unshift()非变异数组方法列表 -
Array.from() - 从一个可迭代对象创建一个数组Array.isArray() - 检查变量是否为数组Array.of()- 创建一个数组;功能版本[]Array.prototype.concat() - 将多个数组组合成一个新的单个数组Array.prototype.entries() - 获取键/值对的迭代器Array.prototype.every() - 检查每个值是否与函数匹配Array.prototype.filter() - 创建一个匹配过滤器的值数组Array.prototype.find() - 使用函数查找值Array.prototype.findIndex() - 使用函数查找值的索引Array.prototype.flatMap() - 使用映射函数创建一个新数组Array.prototype.forEach() - 为每个值运行一个副作用Array.prototype.includes() - 检查数组是否包含一个值Array.prototype.indexOf() - find the index of a value by valueArray.prototype.join() - combine values into a string using a separatorArray.prototype.keys() - get iterator of keysArray.prototype.lastIndexOf() - find the index of a value by value, starting at the endArray.prototype.map() - create a new array using a mapping functionArray.prototype.reduce() - fold over each value, producing a new valueArray.prototype.reduceRight() - fold over each value, starting from the right, producing a new valueArray.prototype.slice() - select a subarrayArray.prototype.some() - check if some value matches a functionArray.prototype.toLocaleString() - string representation of the array, uses toLocaleString on valuesArray.prototype.toString() - string representation of the array, uses toString on valuesArray.prototype.values() - get iterator of valuesArray.prototype[@@iterator]() - get default iterator| 归档时间: |
|
| 查看次数: |
441 次 |
| 最近记录: |