Zahirul Haque Zahirul Haque - 1 year ago 69
AngularJS Question

How to convert dynamic js object into single line string?

I am facing problem to convert a dynamic object into a single line string. My Object is as follows:

var data= {0: "How many colors do you have?",
1: "How many stock do you have?",
2: "Do you provide separate price?"

I need to convert that object into the followings:

var message = 'How many colors do you have? How many stock do you have? Do you provide seperate price?';

Note: the object is not fixed to that three only, it change dynamically, so it becomes 3, 4, 5 or any other number of data.

Answer Source

Try this :

var message = "";
for(var i = 0;i < Object.keys(data).length;i++){
   message += data[i]+" ";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download