javascript - Iterate over nested objects and concatenate to string using Lodash -


I am using a lot of objects to make the object easier. I have an object with three nested objects inside. I I want to repeat through, connect all my children together in all related combinations, while using only one copy list.

My object looks like this:

  {"List_1": {"1": ".cat-3", "2": ".cat-5 "," 3 ":" .cat-7 "}," list_2 ": {" 1 ":". "," 3 ":" .eyes-brown "}," list_3 ": {" 1 ":" Jazz "," 2 ":" commercial. "," 3 ":" .- hop "}}  

The output I want to get is:

  .cat-3.eyes-blue.jazz .cat-3 eyes- blue.commercial .cat-3.eyes-blue.hip-hop  

order is not important What is important is that if only one value from each list_ object is used in the string then, for example, it will be fine:

  .eyes-blue Jazz.ca T-3 .ees-blue.cat-3.com commercial .hip-hop.eyes-blue.cat -3  

and some other examples:

 < Code> .cat-3.eyes-brown.jazz .cat-5.eyes-brown.hip-hop .cat-7.eyes-blue.hip-hop  

As an array of asset objects array:

  var arrayOfArrays = []; _.each (obj, function (item, key) {var itemVals = []; _.each (item, function (item 2, key 2) {itemVals.push (item2);}); arrayOfArrays.push (itemVals) ;});  

Implement the scope () function as described here:

Implement a function to obtain a random array element:

Function Random Element (array) {Return Array [Math.random () * array.length)];

Implement a function to select random elements from an array of arrays in the form of an align string:

  function randomCombination (arrayOfArrays) {var Output = ""; _.each (arrayOfArrays, function (innerArray) {output + = randomElement (innerArray);}) Return output}  

Now you can get a desired output by doing something like this:

Random Combinations (Shuffle Offerers));

Or, if you want to keep the arrayOfArrays intact:

  randomCombination (shuffle (arrayOfArrays.slice (0)));  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -