Looking to manipulate arrays? Here's a task for you:
const arrayToCheck = ['a', 'b', 'c', 'd'];
We have the main array as follows:
const mainArray = [ {name:'alex', code: 'c'},
{name:'jack', code: 'd'},
{name:'john', code: 'n'},
{name:'mike', code: 'l'}
]
The goal is to update the mainArray with a 'status' property, either 'enable' or 'disable', based on values in arrayToCheck.
Expected output:
[ {name:'alex', code: 'c', status: 'enable'},
{name:'jack', code: 'd', status: 'enable'},
{name:'john', code: 'n', status: 'disable'},
{name:'mike', code: 'l', status: 'disable'}
]
An attempt using map and some methods to achieve this was made:
const output = this.mainArray.map( (fil, i) => {
return arrayToCheck.some( s => {
if (s === fil.Code) {
this.mainArray[i].Status = 'enable'
} else {
this.mainArray[i].Status = 'disable'
}
})
});