Currently, I am attempting to develop a Typescript conditional that verifies if a particular word is already present in the name.
The function in question is as follows:
isOrganic() {
for (let i = 0; i < this.items.length; i++) {
if(this.items[i].organic) {
if (' (Organic)' in this.items){
this.items[i].name = this.items[i].name
} else {
this.items[i].name = this.items[i].name.concat(' (Organic)')
}
}
}
}
The main goal here is to determine whether the ' (Organic)' label is already part of the name. If it is, the name should be used as is. However, if it's missing, it needs to be added. Unfortunately, instead of achieving this result, the label keeps getting appended repeatedly. For instance:
Apple (Organic) (Organic) (Organic) etc...
I'm aware that the issue lies within this specific line:
if (' (Organic)' in this.items)
Despite identifying the problem, I'm struggling to devise an appropriate solution through setting up the conditional statement correctly.