例子:
[
["160514110637d4800f000005"],
["160514110639d4800f000009","160514110639d4800f00000a","160514110639d4800f00000b"],
["160514110639d4800f00000d","160514110639d4800f00000e","160514110639d4800f00000f"]
]
方法:
function doExchange(doubleArrays, fgf) { /// <summary> /// 二维数组 组合方案 /// </summary> /// <param name="doubleArrays" type="type">二维数组</param> /// <param name="fgf" type="type">分隔符</param> /// <returns type=""></returns> if (fgf == undefined) fgf = ","; var len = doubleArrays.length; if (len >= 2) { var len1 = doubleArrays[0].length; var len2 = 0; try { len2 = doubleArrays[1].length; } catch (e) { var x = ""; } var newlen = len1 * len2; var temp = new Array(newlen); var index = 0; for (var i = 0; i < len1; i++) { for (var j = 0; j < len2; j++) { temp[index] = doubleArrays[0][i] + fgf + doubleArrays[1][j]; index++; } } var newArray = new Array(len - 1); for (var i = 2; i < len; i++) { newArray[i - 1] = doubleArrays[i]; } newArray[0] = temp; return doExchange(newArray, fgf); } else { return doubleArrays[0]; } }
结果:
[
"160514110637d4800f000005,160514110639d4800f000009,160514110639d4800f00000d",
"160514110637d4800f000005,160514110639d4800f000009,160514110639d4800f00000e",
"160514110637d4800f000005,160514110639d4800f000009,160514110639d4800f00000f",
"160514110637d4800f000005,160514110639d4800f00000a,160514110639d4800f00000d",
"160514110637d4800f000005,160514110639d4800f00000a,160514110639d4800f00000e",
"160514110637d4800f000005,160514110639d4800f00000a,160514110639d4800f00000f",
"160514110637d4800f000005,160514110639d4800f00000b,160514110639d4800f00000d",
"160514110637d4800f000005,160514110639d4800f00000b,160514110639d4800f00000e",
"160514110637d4800f000005,160514110639d4800f00000b,160514110639d4800f00000f"
]