- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行 forEach()
循环,并且需要 console.log()
。但我想为每次迭代获得不同的颜色。我浏览了文档,但找不到任何东西。有什么办法可以达到同样的效果吗?
let arr = ["a", "ab, "abc"]
arr.forEach(arr, e => {
console.log(chalk.red(e)) //maybe something like - chalk.randColor()
})
最佳答案
你可以尝试这样的事情:
// Create an array of possible colors
const color = ['red', 'green', 'blue', 'magenta', 'cyan', 'gray'];
let arr = ["a", "ab", "abc"]
arr.forEach(arr, e => {
// and get a random color name from the array
// and call the function on it
console.log(chalk[color[Math.floor(Math.random() * color.length)]](e))
})
关于javascript - 在 chalk.js 中的 forEach() 中获取随机颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60350038/
我正在使用chalk版本^1.1.3 不知道为什么它说该方法无法识别: const chalk = require('chalk'), _ = require('lodash'), info
我创建了一个类来处理我的通知。为了更改文本颜色,我使用的包接受以下内容: const chalk = require('chalk'); chalk`{red This text will be re
这是我关于stackoverflow的第一个问题。感谢大家对这个绝对精彩的论坛! 我尝试在 docker 运行中获得一个 vue pwa。我使用 vue-cli 来设置 pwa 应用程序。在本地安装和
我不明白 Chalk 的(NodeJS 模块)语法是如何工作的(这让我很困扰)。我已经广泛搜索了答案,但我没有任何运气,并且可能不知道我需要寻找的技术术语。我已经尝试在 StackOverflow 上
我不明白 Chalk 的(NodeJS 模块)语法是如何工作的(这让我很困扰)。我已经广泛搜索了答案,但我没有任何运气,并且可能不知道我需要寻找的技术术语。我已经尝试在 StackOverflow 上
在尝试使用终端字符串样式包 chalk 时,我没有看到任何结果出现在我的 iTerm2 中。我按照安装包的所有步骤进行操作,但是当我在我的 chalk.js< 中运行基本的 console.log("
在 chalk 2.0 中,可以 use tagged strings : const chalk = require('chalk'); console.log(chalk`{bold some}
我正在运行 forEach() 循环,并且需要 console.log()。但我想为每次迭代获得不同的颜色。我浏览了文档,但找不到任何东西。有什么办法可以达到同样的效果吗? let arr = ["a
假设我有这个: //exp.js const chalk = require('chalk'); console.log(chalk.red('foobar')); 然后我在命令行运行: node e
在我的模块中编写一个 Node CLI 我有一个带有 chalk 的 console.log , 例子: console.log( chalk.green(`${delta}:`), chal
请不要将此标记为重复。我知道我以前问过这个问题,但我的问题没有得到解决。 我已经尝试在构建镜像之前将 RUN npm install --save-dev react-dev-utils 添加到 do
我是一名优秀的程序员,十分优秀!