javascript - angularjs dynamic label name for array inside array push -
i creating array using below format,
angular.foreach(value.data, function(value1, key1) { shiftarraylist.push({ shift: value1.shiftname }); dataarraylist.push({ safedaycount: value1.safedaycount, accidentcount: value1.accidentcount, hazardcount: value1.hazardcount, nearmisscount: value1.nearmisscount }); });
and result dataarraylist like,
"safedaycount": 0, "accidentcount": 0, "hazardcount": 39, "nearmisscount": 0
and continues. need append label name inside foreach , every label need append value1.shiftname
. safedaycount + "_"+value1.shiftname
. safedaycount_x, accidentcount_x, hazardcount_x, nearmisscount_x.
. please me append value.
thanks in advance,
you need prepare object this
var props = [ "safedaycount", "accidentcount", "hazardcount", "nearmisscount" ]; var obj = {}; props.foreach( function(item){ obj[ item + "_" + value1.shiftname ] = value1[ item ]; }); dataarraylist.push( obj );
Comments
Post a Comment