How do I simplify/condense this?

Does anyone know how I would go about reducing the following line of code to somehow include "4, 5, 6, 7, 8" into a single...thingy?
if (this.getItemElements().contains(4) || this.getItemElements().contains(5) || this.getItemElements().contains(6) || this.getItemElements().contains(7) || this.getItemElements().contains(8)) {
(target.def + target.mdf) / 2;
}
else {
target.def;
}
I've already tried the following to no avail...
if (this.getItemElements().contains(4 || 5 || 6 || 7 || 8)) {(target.def + target.mdf) / 2;} else {target.def;}
if (this.getItemElements().contains[4 || 5 || 6 || 7 || 8]) {(target.def + target.mdf) / 2;} else {target.def;}
if (this.getItemElements().contains(4, 5, 6, 7, 8)) {(target.def + target.mdf) / 2;} else {target.def;}
if (this.getItemElements().contains[4, 5, 6, 7, 8]) {(target.def + target.mdf) / 2;} else {target.def;}
if (this.getItemElements().contains([4, 5, 6, 7, 8])) {(target.def + target.mdf) / 2;} else {target.def;}
Code:
var checkIds = [4, 5, 6, 7, 8];
var cond = false;

for (var i ; i < checkIds.length ; i++) {
   if (this.getItemElements().contains(checkId[i]) {
      cond = true;
      break;
   }
}

if (cond) {
   // whatever happens when the condition is true;
else {
   // whatever happens when the condition is false;
}

Well, this is kinda longer, but could accommodate much more than 5 items without adding a single line.
Darn, the issue is that the text box in the plugin settings (I'm using this for Yanfly's Armor Scaling plugin) only allows a certain amount of characters.
How many?

EDIT: A solution would be to create another method in whatever object you're calling the function. That method would accept an array, in which you can put all your items ID, and check if a single one of them checks the condition, thus simply returning a true or false.
Oh snap! I guess there isn't a limit after all...I prolly missed a chunk of code when I copy-pasted it the 1st time around lol. I'm going to try using the code you posted to replace the following.
if (this.getItemElements().contains(1) || this.getItemElements().contains(2) || this.getItemElements().contains(3) && this.getItemElements().contains(4) || this.getItemElements().contains(5) || this.getItemElements().contains(6) || this.getItemElements().contains(7) || this.getItemElements().contains(8)) {
(target.def + target.mdf) / 2;
} else if (!this.getItemElements().contains(4) && !this.getItemElements().contains(5) && !this.getItemElements().contains(6) && !this.getItemElements().contains(7) && !this.getItemElements().contains(8)) {target.def;
} else {
target.mdf;
}
I need something that does:
If (1 or 2 or 3) and (4 or 5 or 6 or 7 or 8)
Right now the game sees it as "1 or 2 or 3 and 4 or 5 or 6 or 7 or 8" but I need it to see "1, 2, 3" as a group and "4, 5, 6, 7, 8" as another group. Any idea how to do that?
So you have two arrays, and want to see if any element from the first array is also present in the second array? You can use the some and includes methods of arrays.

Code:
[4, 5, 6, 7, 8].some(num => this.getItemElements().includes(num))
So you have two arrays, and want to see if any element from the first array is also present in the second array? You can use the some and includes methods of arrays.

Code:
[4, 5, 6, 7, 8].some(num => this.getItemElements().includes(num))
I'm trying to construct an IF statement that returns TRUE if the element(s) from the damage in question contains at least an element from each array. Basically...
Elements 1, 2, & 3 are physical elements (Slashing, Piercing, & Crushing)
Elements 4, 5, 6, 7, & 8 are magical elements (Fire, Frost, Shock, Holy, Shadow)

I'm trying to make the amor value/formula in Yanfly's Armor Scaling to use "(.def + .mdf) / 2" if the damage's element contains something from (1, 2, or 3) AND something from (4, 5, 6, 7, or 8)
If it only contains 1, 2, or 3 -> ".def"
If it only contains 4, 5, 6, 7, or 8 -> ".mdf"
I do this because there will be spells/skills that are multi-element (via Yanfly's Element plugin)
Also, a skill can be magical (as in "physical", "magical", or "certain") and deal Slashing(1), Piercing(2), or Crushing(3) damage
e.g.: Casting a spell that impales the target w/ a stone spike would be a magical spell yet do physical damage.

This is my old code that I used, it worked except if the skill utilized multiple elements.
Physical skills:
if (this.item().damage.elementId >= 4) {(target.def + target.mdf) / 2;} else {target.def;}

Magical skills:
if (this.item().damage.elementId < 4 && this.item().damage.elementId >= 4) {(target.def + target.mdf) / 2;} else if (!this.item().damage.elementId >= 4) {target.def;} else {target.mdf;}
Thank you all for your time, I greatly appreciate it!
Hooray! I figured it out and got everything working perfectly 😀

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-simplify-condense-this.102757/