I'm looking to iterate through the JSON below to create a dynamic form in JavaScript. The challenge is that the keys and values are not the same. How can I accomplish this?
["register_form",
{
"name":{
"fielde":"textfield",
"description":""
},
"pass":{
"pass1":{
"field":"password"
},
"pass2":{
"field_type":"password"
}
},
"mail":{
"field":"textfield",
"description":""
},
"field_first_name":{
"field_type":"textfield",
"description":""
}
}
]
none of these solutions are working for me:
//Get the size of object = no. of fileds to be created
var size = Object.keys(response[1]).length;
console.log("Size..." + size);
console.log("Keys.." + Object.keys(response[1]));
var keys = [];
var model = [];
var label = [];
keys.push(Object.keys(response[1]));
for(var i=0;i<keys.length;i++) {
angular.forEach(response[1].keys[i], function(key, value){
console.log(key + "..." + value);
});