How to Remove a specific items attributes from nested array of object in javascript

Solution for How to Remove a specific items attributes from nested array of object in javascript
is Given Below:

I have an array of objects like given in the example. I have done this in a single array but didn’t know to do this in multiple dimensions arrays or nested arrays. read all these questions

How do I remove a property from a JavaScript object?

How can I remove a specific item from an array?

let array = [
{
   id:1,
   items:
      [
         {id: 1, name:"Aftab", rollno:"1", type:"student"},
         {id: 1, name:"Aftab", rollno:"1", type:"teacher"},
         {id: 1, name:"Aftab", rollno:"1", type:"student"},
      ]
},{
   id:2,
   items:
      [
         {id: 1, name:"Aftab", rollno:"1"},
         {id: 1, name:"Aftab", rollno:"1"},
         {id: 1, name:"Aftab", rollno:"1"},
      ]
},{
   id:3,
   items:
      [
         {id: 1, name:"Aftab", rollno:"1"},
         {id: 1, name:"Aftab", rollno:"1"},
         {id: 1, name:"Aftab", rollno:"1"},
      ]
},]

I want to change the rollno or remove it from items that have the type of teacher.

Changing the rollno when type is teacher.

let arrayData = [
    {
        id: 1,
        items:
            [
                { id: 1, name: "Aftab", rollno: "1", type: "student" },
                { id: 1, name: "Aftab", rollno: "1", type: "teacher" },
                { id: 1, name: "Aftab", rollno: "1", type: "student" },
            ]
    }, {
        id: 2,
        items:
            [
                { id: 1, name: "Aftab", rollno: "1" },
                { id: 1, name: "Aftab", rollno: "1" },
                { id: 1, name: "Aftab", rollno: "1" },
            ]
    }, {
        id: 3,
        items:
            [
                { id: 1, name: "Aftab", rollno: "1" },
                { id: 1, name: "Aftab", rollno: "1" },
                { id: 1, name: "Aftab", rollno: "1" },
            ]
    },
]

arrayData.forEach((node) => {
    node.items.forEach((item) => {
        if(item.type === 'teacher') {
            item.rollno = null;
        }
    })
});

console.log(arrayData)

Deleting the rollno when type is teacher.

let arrayData = [
    {
        id: 1,
        items:
            [
                { id: 1, name: "Aftab", rollno: "1", type: "student" },
                { id: 1, name: "Aftab", rollno: "1", type: "teacher" },
                { id: 1, name: "Aftab", rollno: "1", type: "student" },
            ]
    }, {
        id: 2,
        items:
            [
                { id: 1, name: "Aftab", rollno: "1" },
                { id: 1, name: "Aftab", rollno: "1" },
                { id: 1, name: "Aftab", rollno: "1" },
            ]
    }, {
        id: 3,
        items:
            [
                { id: 1, name: "Aftab", rollno: "1" },
                { id: 1, name: "Aftab", rollno: "1" },
                { id: 1, name: "Aftab", rollno: "1" },
            ]
    },
]

arrayData.forEach((node) => {
    node.items.forEach((item) => {
        if(item.type === 'teacher') {
            delete item.rollno;
        }
    })
});

console.log(arrayData)
let array = [
{
   id:1,
   items:
      [
         {id: 1, name:"Aftab", rollno:"1", type:"student"},
         {id: 1, name:"Aftab", rollno:"1", type:"teacher"},
         {id: 1, name:"Aftab", rollno:"1", type:"student"},
      ]
},{
   id:2,
   items:
      [
         {id: 1, name:"Aftab", rollno:"1"},
         {id: 1, name:"Aftab", rollno:"1"},
         {id: 1, name:"Aftab", rollno:"1"},
      ]
},{
   id:3,
   items:
      [
         {id: 1, name:"Aftab", rollno:"1"},
         {id: 1, name:"Aftab", rollno:"1"},
         {id: 1, name:"Aftab", rollno:"1"},
      ]
}]

const recurse = (arr, repl) => arr.map(item => 
  item.items instanceof Array 
    ? {
        items: recurse(item.items, repl)
      }
    : repl(item)
)
const updatedArray = recurse(array, (item) => (
  item.type !== 'teacher' ? item: {...item, rollno: 'updated whatever'}) 
);
console.log('updatedArray', updatedArray);