我需要像這樣從這兩個陣列中獲得這種組合。
const array1 = [ '0', '4', '8', '16', '24', '32', '40', '48', '56', '64' ]
const array2 = [ 'p', 'px', 'py', 'pt', 'pe', 'pb', 'ps', 'm', 'mx', 'my', 'mt', 'me', 'mb', 'ms']
// output
// const combine = {p: [p-0, p-4, p-8,...], px: [px-0, px-4, px-8,...].....}
// we can access values like this
// combine.p
// combine.px
uj5u.com熱心網友回復:
您可以將第一個陣列映射為關鍵廣告前綴,并將另一個陣列的值作為后綴。
const
array1 = [ '0', '4', '8', '16', '24', '32', '40', '48', '56', '64' ],
array2 = [ 'p', 'px', 'py', 'pt', 'pe', 'pb', 'ps', 'm', 'mx', 'my', 'mt', 'me', 'mb', 'ms'],
result = Object.fromEntries(array2.map(k => [k, array1.map(v => [k, v].join('-'))]));
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/440204.html
標籤:javascript 数组 组合
