I am looping an object to get values for a particular set (here it is _source). Here in the example I would like to loop the object and get the _source values from the object and push in array.
I am using angular.forEach for this. However when I use this function I am not getting an array. I am looking for an output like:
myarr[0] = [value1:0, value2: "2", value3:"MON"]
myarr[1] = [value1:1, value2:"3", value3: "MON1"]
My code:
Mysvc.getSourceValues()
.success(function (data) {
srcobj= data.hits.kal;
angular.forEach(srcobj, function(value, key) {
var sourcevalues= value._source;
//this.push(key + ': ' + value);
});
})
.error(function (error) {
$log.info("Unable to load values");
})
My srcobjdata:
{
"kal": [
{
"_index": "log2015.18",
"_type": "MT_DETAIL",
"_sc": null,
"_source": {
"value1": 0,
"value2": "2",
"value3": "MON"
},
"sort": [
1
]
},
{
"_index": "logw-2015.18",
"_type": "MT_DETAIL",
"_sc": null,
"_source": {
"value1": 1,
"value2": "3",
"value3": "MON1"
},
"sort": [
2
]
},
{
"_index": "log-2015.18",
"_type": "MT_DETAIL",
"_sc": null,
"_source": {
"value1": 3,
"value2": "265",
"value3": "MON2"
},
"sort": [
3
]
},
{
"_index": "log2015.18",
"_type": "MT_DETAIL",
"_sc": null,
"_source": {
"value1": 4,
"value2": "5",
"value3": "MON5"
},
"sort": [
1
]
},
{
"_index": "log2015.18",
"_type": "MT_DETAIL",
"_sc": null,
"_source": {
"value1": 7,
"value2": "3",
"value3": "MON8"
},
"sort": [
1
]
}
]
}