
// 数据源
var target = {
state1: ['1', '2'],
state2: ['01', '02', '03'],
state3: ['001','002']
} stackSituation(target) function stackSituation (data) {
var targetKeys = Object.keys(data)
var target = faker = []
if (targetKeys.length) {
target = targetKeys.map((key) => data[key])
faker = target[0]
} target.forEach((itemArr, index, currentArr) => {
faker = js(faker, currentArr[index + 1])
})
function js(arr1, arr2){
var arr1 = arr1 || []
var arr2 = arr2 || []
faker = []
for(var i = 0;i < arr1.length; i++){
if (!arr2.length) {
faker.push(arr1[i])
} else {
for(var j = 0; j < arr2.length; j++){
faker.push(arr1[i] + '_' +arr2[j]);
}
}
}
return faker
}
var result = faker.map((item) => item.split('_'))
console.table(result)
return result
}