我面临将动态对象转换为单行字符串的问题。我的对象如下:
var data= {0: "How many colors do you have?",
1: "How many stock do you have?",
2: "Do you provide separate price?"
};
我需要将该对象转换为以下内容:
var message = 'How many colors do you have? How many stock do you have? Do you provide seperate price?';
注意:对象不仅仅固定为三个,它会动态变化,因此它变为3,4,5或任何其他数量的数据。
答案 0 :(得分:2)
var res = Object.keys(data)
.map(function (key) {
return data[key];
})
.join(' ');
答案 1 :(得分:0)
试试这个:
var message = "";
for(var i = 0;i < Object.keys(data).length;i++){
message += data[i]+" ";
}