I have the array as follows, I want to first check if the record in array already exists, and then push the similar record.
arr1 = [{
'Name': 'Ken',
'Id' : 123,
'Units' : 100
}, {
'Name': 'Kris',
'Id': '223',
'Units' : 100
}, {
'Name': 'Ben',
'Id': '229',
'Units' : 100
},
{
'Name': 'Alex',
'Id': '222',
'Units' : 100
}]
Now suppose I want to add a similar record
{
'Name': 'Ken',
'Id' : 123,
'Units' : 50
}
Here only the value of Units have been changed and sometimes it may also remain same.
What I want is remove the initial similar record (check by Id) and push the new one.
So my final array should be like
arr1 = [{
'Name': 'Ken',
'Id' : 123,
'Units' : 100
}, {
'Name': 'Kris',
'Id': '223',
'Units' : 100
}, {
'Name': 'Ben',
'Id': '229',
'Units' : 100
},
{
'Name': 'Alex',
'Id': '222',
'Units' : 100
}]