Array.prototype.filter() method creates a new array with all elements that pass the test implemented by the provided function. Like following:
var selectedgroup = [ {ID:1, selected:true},{ID:2, selected:false} ];
var mainarr = [ {ID:1, mainid:25, name:'ser', pID:545},{ID:2, mainid:84, name:'ferdi', pID:678},{ID:3, mainid:88, name:'ferSER', pID:656}];
var newarr = mainarr.filter(function(eachArr){
for (var i = 0; i < selectedgroup.length; i++){
if(selectedgroup [i].ID === eachArr.ID){
return true;
} }})
If selectedgroup array can have many values, you can use map to get all ids first to avoid inner loop and then filter with them as @CHANist said.
For your reference: Array.prototype.map().
Thus, the code would become
var selectedgroup = [ {ID:1, selected:true},{ID:2, selected:false} ];
var mainarr = [ {ID:1, mainid:25, name:'ser', pID:545},{ID:2, mainid:84, name:'ferdi', pID:678},{ID:3, mainid:88, name:'ferSER', pID:656}];
var ids = selectedgroup.map(function(obj){ return obj.ID});
var newarr = mainarr.filter(function(eachArr){
for (var i = 0; i < selectedgroup.length; i++){
if(ids.indexOf(eachArr.ID) !== -1){
return true;
} }})