I am working with an array where I need to create a function that will loop through the array and reset the 'val' for all items except the second one (index 1). I attempted to use the forEach method but I am struggling with the implementation.
names = [
{
name: 'first',
inputType: 'number',
val: void 5
},
{
name: 'second',
inputType: 'number',
val: void 2
},
{
name: 'third',
inputType: 'text',
val: void 3
}
]
Here is what I have tried:
resetValues() {
let names = this.names
names.forEach((name:any, index:number)=>{
if(index===1){
name[1] = name[1].val
} else{
name.val = ''
}
})
}