[Solved] Removing objects from an array, objects having value which match a regex pattern


You can use Array.filter to achieve that.

var arr = [{
    type: "parent",
    Level: "1-1",
  },{
    type: "parent",
    Level: "1-2",
  },{
    type: "child",
    Level: "1-2-1",
  },{
    type: "child",
    Level: "1-2-2",
  },{
    type: "child",
    Level: "1-2-3",
  },{
    type: "child",
    Level: "1-4-3",
  },{
    type: "parent",
    Level: "1-3",
  }
];

var nodetoberemoved = "1-2";
var result = arr.filter(function(elem){
        return !elem.Level.indexOf(nodetoberemoved+"-")==0;
});

console.log(result)

7

solved Removing objects from an array, objects having value which match a regex pattern