I have a JSON object. For example:
{
"id": 1,
"name": "Name",
"surname": "Surname",
"number": "111111111"
}
How to make a string from this JSON object using javascript, that looks like this.
Name Surname 111111111
You can use for...in statement to iterating values of object. In loop add every value to string.
var json = {
"id": 1,
"name": "Name",
"surname": "Surname",
"number": "111111111"
};
var str = "";
for (var key in json) {
str += (key != "id") ? (json[key] + " ") : "";
}
console.log(str);
Supossing that you have this json stored in a var. for example:
var jsonObject = {
"id": 1,
"name": "Name",
"surname": "Surname",
"number": "111111111"
}
You can do something like that:
var myStringResult = jsonObject.name + ' ' + jsonObject.surname + ' ' + jsonObject.number;