I´m trying to remove an Object in an array.
The situation is the following.
In the code i generate a new Post object, which i`ll push to an post_array
var field = "Kommentar";
var objectKey = 1;
var new_post_obj = {objectKey: objectKey, field: field, value: new_value, type: "text"};
post_array.push(new_post_obj);
Thats working fine. I do not want to have an new_post_obj in the post_array with the same objectKey and the same field. For that i`d like to remove the post Objects in the post_array which have the same objectKey and field as a new Object i want to Post. And then push the new_post_obj.
For example the post_array has following data:
[
{objectKey: "1", field: "Kommentar1", value: "kommentar123", type: "text"},
{objectKey: "1", field: "Color", value: "red", type: "text"}
]
My new_post_obj has this new Data
{objectKey: "1", field: "Kommentar1", value: "kommentar123456", type: "text"}
Now i need to remove the old data with objectKey: 1 and field: "Kommentar1"
I tried the following code:
post_array = $.grep( post_array, function(n) {
return (n.field != field && n.objectKey != objectKey);
});
After that i excpect that my post_array has only this value:
{objectKey: "2", field: "Color", value: "red", type: "text"}
But it`s empty. How can i solve this?