<script> let str = "Hello,World,JavaScript,Node.js"; let arr = str.split(",", 2); // 只返回两个元素 alert(arr); // 输出: ["Hello", "World"] alert(arr[0]); alert(arr[1]); </script>
运行结果:
Hello, World Hello World