Required to splice specific element value in an array based on the condition.
Both the below code does the same job and yields the correct results. But couldn't figure out how to reduce coding structure with ECMAScript and which is performance oriented considering an array would have atleast 1.5k or even larger
This is with ECMAScript
this.candidateColumns.filter(item => item === 'Certificate').map(m => {
if (!this.showControlsBasedOnPrivileges('CERTIFICATEPRINT')) {
this.candidateColumns = this.candidateColumns.filter(item => item !== 'Certificate')
}
});
This is simple forEach Loop code
this.candidateColumns.forEach((currentValue, index) => {
if (currentValue === 'Certificate' && !this.showControlsBasedOnPrivileges('CERTIFICATEPRINT')) {
this.candidateColumns = this.candidateColumns.filter(item => item !== 'Certificate')
}
});
Any other Built In function Approach could be done for better performance or readability