输入:“颜色”:{“ orange”:“多汁的颜色”,“ skyBlue”:“天空颜色”,“ black”:“深色”,“ white”:“和平的颜色”,},
想要输出:多汁的颜色,天空的颜色,深色,平静的颜色。
任何帮助都会有所帮助!谢谢:)
const colors = {
orange: "juicy color",
skyBlue: "sky color",
black: "dark color",
white: "peaceful color"
};
const ColorsString = Object.values(colors).join(", ");
尝试一下
this.output = Object.keys(this.colors).map(val => this.colors[val]).join(', ');
尝试这样:
colors = {
orange: "juicy color",
skyBlue: "sky color",
black: "dark color",
white: "peaceful color"
};
数组输出
this.arrayOutput = Object.keys(this.colors).map(item => this.colors[item]);
字符串输出
output: string = "";
constructor() {
Object.keys(this.colors).forEach(item => {
this.output += this.colors[item];
this.output += ","
});
}