数组的常用方法有哪些?
参考答案
增删改(改原数组)
push/pop、shift/unshift、splice、sort、reverse、fill、copyWithin
不改原数组
concat、slice、join、flat/flatMap、toReversed/toSorted/toSpliced(ES2023)
遍历与转换
forEach、map、filter、reduce/reduceRight、some、every、find/findIndex/findLast、keys/values/entries
查找判断
indexOf/lastIndexOf、includes、at、Array.isArray
静态
Array.from、Array.of、Array.isArray
要点:区分是否修改原数组;sort 默认按字符串比较需传比较函数;类数组用 Array.from/展开转换。