我想將下面的輸入字符串拆分爲輸出字符串。
輸入= 'ABC1:ABC2:ABC3:ABC4'
輸出= [ 'ABC1', 'ABC2:ABC3:ABC4']字符串第一次拆分
let a = 'ABC1:ABC2:ABC3:ABC4'
a.split(':', 2); // not working returning ['ABC1','ABC2']
我想將下面的輸入字符串拆分爲輸出字符串。
輸入= 'ABC1:ABC2:ABC3:ABC4'
輸出= [ 'ABC1', 'ABC2:ABC3:ABC4']字符串第一次拆分
let a = 'ABC1:ABC2:ABC3:ABC4'
a.split(':', 2); // not working returning ['ABC1','ABC2']
您可以使用此功能,可以在所有的瀏覽器
var nString = 'ABC1:ABC2:ABC3:ABC4';
var result = nString.split(/:(.+)/).slice(0,-1);
console.log(result);
感謝...... :-) – Nithin
let a = 'ABC1:ABC2:ABC3:ABC4'
const head = a.split(':', 1);
const tail = a.split(':').splice(1);
const result = head.concat(tail.join(':'));
console.log(result); // ==> ["ABC1", "ABC2:ABC3:ABC4"]
console.log('ABC1:ABC2:ABC3:ABC4'.replace(':','@').split('@'));
https://es6console.com/j4zc4icr/ –