我有一个十六进制值数组,
"colors": ["#d5dd90","#e6bb45","#ef9770"]
我可以像这样注销这些:
colors.forEach((value)=>{
console.log('%cABC', `background: ${value};`);
})
这会产生 3 个单独的
console.log()
条目:
ABC
______________
ABC
______________
ABC
______________
每个“ABC”都有不同的颜色,一个
log()
代表数组中的每一项。
我想做的是将每一项写在一行中,如下所示:
ABC
ABC
ABC
______________
所以基本上每个数组都有一个
log()
调用,每个数组都有其各自的颜色。
const colors = ["#d5dd90","#e6bb45","#ef9770"];
console.log(colors.map(c => `%c${c}`).join(''), ...colors.map(c => `background: ${c};`));
Open the browser console to see the result