标签:
例子:
[
["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 = doubleArrays[1].length; 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); if (len > 2) { newArray[1] = doubleArrays[2]; } 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"
]
标签:
原文地址:http://www.cnblogs.com/OleRookie/p/5498330.html