-1
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 = [a-b:c-d:e-f];

How can it be acheived either using javascript or jquery?

cs95
  • 379,657
  • 97
  • 704
  • 746
Vignesh
  • 1
  • 4
  • Possible duplicate: https://stackoverflow.com/a/32066127/4034148 – wbdlc Jan 18 '19 at 12:21
  • Possible duplicate of [Merge multiple arrays to one array in jquery](https://stackoverflow.com/questions/32066001/merge-multiple-arrays-to-one-array-in-jquery) – wbdlc Jan 18 '19 at 12:21

1 Answers1

0

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 ["a-b", "c-d", "e-f"]), then the last join creates a string out of them by joining the strings using colons.

Bálint
  • 4,009
  • 2
  • 16
  • 27