Skip to content

Latest commit

 

History

History
30 lines (19 loc) · 915 Bytes

File metadata and controls

30 lines (19 loc) · 915 Bytes
标题 标签
reverseString(反转字符串) string(字符串)

反转字符串。

  • 使用展开运算符 (...) 和 Array.prototype.reverse() 来反转字符串中字符的顺序。
  • 使用 Array.prototype.join() 组合字符以获得字符串。
const reverseString = str => [...str].reverse().join('');

调用方式:

reverseString('foobar'); // 'raboof'

应用场景

以下是一个实战示例:

结果如下:

<iframe src="codes/javascript/html/reverse-string.html"></iframe>