How do you reverse a string in place in JavaScript?

前端 未结 30 2414
猫巷女王i
猫巷女王i 2020-11-22 00:29

How do you reverse a string in place (or in-place) in JavaScript when it is passed to a function with a return statement, without using built-in functions (.reverse()<

30条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-22 00:42

    In ES6, you have one more option

    function reverseString (str) {
      return [...str].reverse().join('')
    }
    
    reverseString('Hello');
    

提交回复
热议问题