This is array of array data in a variable 'data'. I would like to convert array of array data to JSON using AngularJS and use in View using $scope object
$scope.data =[["Name", "Age", "Address"],
[ "A", "43", "CA" ],
[ "B", "23", "VA" ],
[ "C", "24", "NY" ]]
Function wrote to convert array of array to JSON:
$scope.jsonData = function () {
var result = [];
var keys = data[0];
for (var i = 1; i < data.length; i++) {
var item = {};
item[keys[0]] = data[i][0];
item[keys[1]] = data[i][1];
item[keys[2]] = data[i][2];
result.push(item);
}
return result
};
I am not seeing JSON output, where am I doing wrong?
Desired Output:
[
{
"Name": "A",
"Age": "43",
"Address": "CA"
},
{
"Name": "B",
"Age": "23",
"Address": "VA"
},
{
"Name": "C",
"Age": "24",
"Address": "NY"
}
]