I'm trying to use set.has() in lightning web components and it seems to be not working.
Below is the code snippet..
sStatusToVerify = 'Complete';
var setStatusVals = [...new Set(this.lstAllData.map(obj => obj.sStatus))];
console.log('setStatusVals : ',setStatusVals);
console.log('Contains?? : ' ,setStatusVals.has(sStatusToVerify));
setStatusVals consoles all the values and it contains "Complete". However, the next console is not printed at all. It should ideally print true. Not sure why this is not working.
What is wrong here?
The problem with your solution is , you are converting the set back to array by using the spread operator [... new Set()]
and array does not has has
method . Hence the issue
var sStatusToVerify = 'Complete';
var arr=[{sStatus:'Complete'},{sStatus:'Start'},{sStatus:'InProgress'}];
var setStatusVals = new Set(arr.map(obj => obj.sStatus));
console.log(setStatusVals.has(sStatusToVerify));