getProcessedParams = (paramAttributes, current = []) => {
// null check
if (!paramAttributes || !Object.keys(paramAttributes).length) {
return [];
}
const attributeIds = Object.keys(paramAttributes);
// get current processing attribute
const attributeId = attributeIds[0]
const attributesValueIds = paramAttributes[attributeId];
// keep only remaing
const remaining = Object.fromEntries(Object.entries(paramAttributes).slice(1));
const remainingLength = Object.keys(remaining).length;
// result
let result = [];
// loop over attribute value id & add
attributesValueIds.forEach((attributesValueId, index) => {
// make shallow copy
let newCurrent = current.slice(0);
// push
newCurrent.push(attributesValueId);
// check if more attributeValueIds of another attribute can be added
if (remainingLength) {
const resultOfRemaining = getProcessedParams(remaining, newCurrent);
// merge with current result
result = result.concat(resultOfRemaining);
} else {
// to result to create array of attributesValues
result.push(newCurrent);
}
})
return result;
}
const params = {
"attributesValueId": {
"5": [13, 14, 15],
"6": [22, 23],
"7": [28]
}
}
console.log(getProcessedParams(params.attributesValueId))
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.