Ashutosh Jha February 2016

JSON merge on a condition in angularJs

How to merge json on a condition ?

var a = {
id: 100 , 
name : ashu , 
rNo : 42
}

var b = {
studentID : 100 , 
Totalmarks : 88
}


var finalResult = {
id: 100 , 
name : ashu , 
rNo : 42 ,
studentID : 100 , 
Totalmarks : 88, 
}

here i have given small example but i have json with lots of data . like here is example where i want to merge where id == studentID in numer of records . can i do this by using angular.merge ?? or any other solution ?

Answers


praveen February 2016

My suggestion is to Use angular.merge() method to merge two json objects.

if(b.studentID==finalResult.id)
{
    var mergeObj= angular.merge(b,finalResult);
    console.log(mergeObj);
}

Post Status

Asked in February 2016
Viewed 1,444 times
Voted 7
Answered 1 times

Search




Leave an answer