In my JavaScript code, I have added objects to an array, each with a new property called "Type". Now, I need to extract the objects from the array that have this "Type" property and put them into a new array.
var arr = [
{ID: 1, Name: "Name1"},
{ID: 2, Name: "Name2"}]
var newObject = {
ID: 3,
Name: 'Test',
Type: 'New'
};
arr.push(newObject);
I attempted
var filteredArray = arr.filter(item => item.Type !== null);
However, this code returns all objects from the original array.
The desired result should be
[{ ID: 3, Name: "Test", Type: "New" }]