js reverse
时间: 2023-10-12 14:05:24 浏览: 133
js代码-js数组元素反转 reverse
Sure! To reverse a string in JavaScript, you can use the `split()`, `reverse()`, and `join()` methods.
Here's an example:
```javascript
const str = 'Hello, World!';
const reversedStr = str.split('').reverse().join('');
console.log(reversedStr);
```
This code will output: `!dlroW ,olleH`
Explanation:
- `split('')` splits the string into an array of individual characters.
- `reverse()` reverses the order of the array elements.
- `join('')` joins the reversed array elements back into a string.
Let me know if you have any more questions!
阅读全文