=> "string "
console.log(str.trimRight()); // => " string"
对于Web兼容性,trimLeft() 和trimRight() 将保留为...3. flat() and flatMap()
flat() 方法可以将多维数组展平成一维数组
const arr = ['a', 'b', ['c', 'd']];
const flattened =...arr.flat();
console.log(flattened); // => ["a", "b", "c", "d"]
以前,我们经常使用reduce()或concat()来展平多维数组...flattened = arr.flat();
console.log(flattened); // => ["a", "b", "c", "d"]
flat() 还接受一个可选参数,该参数指定嵌套数组应该被展平的级别数...=> [[4], [20], [26]]
console.log(arr.flatMap(value => [Math.round(value)]));
// => [4, 20, 26]
数组将被展平的深度级别为