一些方法:

167 阅读1分钟

split() 方法用于把一个字符串分割成字符串数组。 split(separator,howmany) 第一参数:从该参数指定的地方分割 stringObject。 第二参数:该参数可指定返回的数组的最大长度 如果把空字符串 ("") 每个字符之间都会被分割。

reverse() 方法用于颠倒数组中元素的顺序。 该方法会改变原来的数组,而不会创建新的数组。

join() 方法用于把数组中的所有元素放入一个字符串。 join(separator) separator 可选。指定要使用的分隔符。如果省略该参数,则使用逗号作为分隔符。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var  message =  'Hello Vue.js!'
        console.log(message.split(''));// ["H", "e", "l", "l", "o", " ", "V", "u", "e", ".", "j", "s", "!"]
        console.log(message.split(' '));//["Hello", "Vue.js!"]
        console.log(message.split('').reverse());//["!", "s", "j", ".", "e", "u", "V", " ", "o", "l", "l", "e", "H"]
        console.log(message.split('').reverse().join());//!,s,j,.,e,u,V, ,o,l,l,e,H   默认不写是逗号
        console.log(message.split('').reverse().join(''));//什么字符都不用连接
        
         
    </script>
</body>
</html>