I have a list of data items each containing one of many different nested property values like A or B from the same property like e.g. employeeType. I need to create a new array that only contains objects thats value for employee.employeeType  equals "B".
const data = [{
  "id": 80,
  "employee": {
    "employeeType":"A"
  }
}, {
  "id": 250,
  "employee": {
    "employeeType" :"B"
  }
}, {
  "id": 263,
  "employee": {
    "employeeType" :"A"
  }
}, {
  "id": 267,
  "employee": {
    "employeeType" :"A"
  }
}, {
  "id": 272,
  "employee": {
    "employeeType" :"A"
  }
}, {
  "id": 281,
  "employee": {
    "employeeType" :"B"
  }
}];
            
Expected ouput
[{
  "id": 250,
  "employee": {
    "employeeType" :"B"
  }
}, {
  "id": 281,
  "employee": {
    "employeeType" :"B"
  }
}]
I tried this but get an error of filter of undefined
const updatedData = data.map((element) => {
    return {...element, subElements: element.subElements.filter((subElement) => 
    subElement.employeeType === "B")}
 })
 
     
     
    