http://jsfiddle.net/0444046b/12/
I have a complex Array of objects, each object has it's own tag Array.
I also have just an object which should match one of the objects in the tag Array, and if so remove that tag.
Got some help here, however my example there was too simple, so far no luck with this below.
Basically I have the object tag
and I need to remove it from the tags
Array inside of tagsArray
.
var tagsArray = [{
name: "group1",
tags: [
{
name: "1",
tag_id: "1234"
},
{
name: "2",
tag_id: "5678"
},
{
name: "3",
tag_id: "9012"
}
]
},
{
name: "group2",
tags: []
}
];
console.log(tagsArray[0]);
// Need to find this inside of tags inside of tagsArray and remove it:
var tag = {
name: "3",
tag_id: "9012"
}
var temp_array = [];
temp_array.push(tag);
var map = {};
tagsArray.forEach(function(obj, index) {
map[obj.tag_id] = index;
});
console.log(map);
temp_array.forEach(function(obj) {
if ( obj.tag_id ) {
tagsArray.splice(tagsArray[map[obj.tag_id]]);
console.log(tagsArray);
}
});