I have a JSON dataset and I want to update a specific value using Angular.js or JavaScript. Here is my code snippet:
$http({
method:'POST',
url:"php/getFilterCodeData.php",
data:filterData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
console.log('filter',response.data);
$scope.last=[];
for(var i=0;i<response.data.length;i++){
$scope.arrCode=response.data[i].generated_code.split(',');
}
//console.log('arr',$scope.arrCode);
for(var i=0;i<$scope.arrCode.length;i++){
$scope.last.push($scope.arrCode[i].split("_").pop());
}
//console.log('last',$scope.last);
var newStr=$scope.last[0]+"-"+$scope.last[$scope.last.length-1];
//console.log('new str',newStr);
},function errorCallback(response) {
})
After logging the following data, this is what appears on the console:
filter [{
customer_name: "Big-Bazar"
expired_date: "23-12-2015"
generated_code: "medilink_global_01,medilink_global_02,..."
no_of_voucher: "40"
status: "generated"
voucher_amount: "3000"
voucher_code_id: "13"}]
To achieve the desired result, I need to replace the generated_code:
value with newStr
. The expected outcome should be:
generated_code:01-40