I have a response in JSON format form a PHP file through an AJAX call.
console.log(data["json"]);
[{"value":"23","label":"Assorted Juices"},{"value":"24","label":"Water"},{"value":"25","label":"Beers"},{"value":"26","label":"Carbonated Drinks"},{"value":"27","label":"Instant Beverages "},{"value":"28","label":"Energy Drinks"}]
I was able to loop through the JSON
var subCategory = data["json"];
//console.log(subCategory);
var obj = $.parseJSON(subCategory);
$.each(obj, function() {
$label = this['label'];
$value = this['value'];
});
I need a build an Object like below in javascript. How can i adjust the above loop to generate an object like this.
var data = [
{ label: 'Water', value: '24' },
{ label: 'Energy Drinks', value: '28' },
]