您可以使用自己的函数来获取所有组合。
以下是代码-
function combination(values) { function * combinationRepeat(size, v) { if (size) for (var chr of values) yield * combinationRepeat(size - 1, v + chr); else yield v; } return [...combinationRepeat(values.length, "")]; } var output = combination([4,5]); console.log(output);要运行上述程序,您需要使用以下命令-
node fileName.js.在这里,我的文件名为demo306.js。
输出结果
这将产生以下输出-
PS C:\Users\Amit\javascript-code> node demo306.js [ 44, 45, 54, 55 ]