我有一个像这样的javascript数组:

["444c-0300-0b29-1817", "444c-0300-0b29-0715,444c-0300-0b29-0720"]


我想这样:

["444c-0300-0b29-1817", "444c-0300-0b29-0715", "444c-0300-0b29-0720"]


我需要一个最佳实践。
感谢您的帮助。

最佳答案

您可以将Array#reduceArray#concat一起使用



var data = ["444c-0300-0b29-1817", "444c-0300-0b29-0715,444c-0300-0b29-0720"],
    single = data.reduce(function (r, a) {
        return r.concat(a.split(','));
    }, []);

console.log(single);





ES6



var data = ["444c-0300-0b29-1817", "444c-0300-0b29-0715,444c-0300-0b29-0720"],
    single = data.reduce((r, a) => r.concat(a.split(',')), []);

console.log(single);

10-07 23:37