I have two arrays that are dynamic which could change at any time. For example:
var vehicleColor = "red,green,blue,white".split(",");
var vehicleType = "Truck,Car,Bus".split(",");
How can I incorporate these arrays to make a javascript array in this format for my graph.
var links = [
{source: vehicleColor[0], target: vehicleType[0]},
{source: vehicleColor[1], target: vehicleType[0]},
{source: vehicleColor[2], target: vehicleType[0]},
{source: vehicleColor[3], target: vehicleType[0]},
{source: vehicleColor[0], target: vehicleType[1]},
{source: vehicleColor[1], target: vehicleType[1]},
etc...
]
Basically I need an array that loops through all of the elements in both arrays but creating a separate line for each one.
I've tried:
links = links.map(x => ({source:vehicleColor, target:vehicleType}));
but this doesn't get me each element in a separate line.
The map method gives me this output
var links = [
{source: ["red","green","blue","white"], target: ["Truck","Bus","Car"]},
]