数组
结果
代码
<template>
<div></div>
</template>
<script>
export default {
name: "",
components: {},
props: {},
data() {
return {};
},
filters: {},
computed: {},
watch: {},
created() {},
mounted() {
function generateCombinations(arrays, prefix = '') {
if (arrays.length === 0) {
return [prefix];
}
const [firstArray, ...restArrays] = arrays;
const combinations = [];
for (const value of firstArray.value) {
const newPrefix = prefix ? `${prefix}/${value}` : value;
const subCombinations = generateCombinations(restArrays, newPrefix);
combinations.push(...subCombinations);
}
return combinations;
}
const arrays = [
{ value: ['苹果', '三星'], name: '手机' },
{ value: ['红色', '蓝色'], name: '颜色' },
{ value: ['10G', '20G'], name: '大小' },
{ value: ['大型', '小型'], name: '电池' },
];
const combinations = generateCombinations(arrays);
console.log(combinations);
},
beforeDestroy() {},
methods: {},
};
</script>
<style scoped lang="less">
</style>