简体   繁体   English

如何合并三个数组并用“:”连接它们

[英]how to merge three arrays and join them with ':'

var a = ["a","b"];
var b = ["c","d"];
var c = ["e","f"];

So these are the three arrays.所以这是三个数组。 I want the output as: var d = [ab:cd:ef];我希望输出为: var d = [ab:cd:ef];

How can it be acheived either using javascript or jquery?如何使用 javascript 或 jquery 实现?

You can do it using a map and joins您可以使用地图和连接来完成

var d = [ a, b, c ].map(sub => sub.join("-")).join(":");

The first map takes every subarray and joins them (d is ["ab", "cd", "ef"] ), then the last join creates a string out of them by joining the strings using colons.第一个映射获取每个子数组并连接它们(d 是["ab", "cd", "ef"] ),然后最后一个连接通过使用冒号连接字符串来创建一个字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM