I am trying to create an object based on the contents of another object. I have an object that contains the following key/values:
var inputObject = {
"color": [
"black",
"red",
"green"
],
"bottom": [
"A",
"B",
"C",
"D",
],
"top": [
"L",
"M"
]
}
I would like to modify this object so that it creates a dynamic number of keys. Here is my intended output:
var outputObject = {
"blackBottom": [
"A",
"B",
"C",
"D",
],
"redBottom": [
"A",
"B",
"C",
"D",
],
"greenBottom": [
"A",
"B",
"C",
"D",
],
"blackTop": [
"L",
"M"
],
"redTop": [
"L",
"M"
],
"greenTop": [
"L",
"M"
]
}
Where the following conditions are met:
- Should there be no colors inside the
"color"key, or the"color"key not exist, then create all 4"color" + "Bottom" and "Top" - Should there be only one color inside the
"color"object, then only create that"color" + "Bottom" and "Top" - Should there be only no entries in
"Bottom", then only create the"color" + "Bottom"
How do I create the outputObject?