Checking for and adding an actor to party?

I'm trying to do the following :

If Actor 2 is in party then add Actor 3
And If Actor 3 is in party then add Actor 2

The following code does not seem to work ... any help would be appreciated !

Code:
if ($gameParty.members().contains($gameActors.actor(2)) > -1) {
    $gameParty.addActor(3);
    $gamePlayer.refresh();
} else if ($gameParty.members().contains($gameActors.actor(3)) > -1) {
    $gameParty.addActor(2);
    $gamePlayer.refresh();
}
why are you trying to do this by javascript?
It would probably be easier to do this with event commands (and possibly switches to remember actor status if you don't like to loop control variable to check for actors)
Because I'm using it in conjunction with a on equip / on unequip plugin. Equiping a weapon adds an actor to the party but if the actor is already present then it adds another actor.
The 'contains' method will return a boolean (true or false), not an integer.

Code:
if ($gameParty.members().contains($gameActors.actor(2))) {
   $gameParty.addActor(3);
   $gamePlayer.refresh();
} else if ($gameParty.members().contains($gameActors.actor(3))) {
   $gameParty.addActor(2);
   $gamePlayer.refresh();
}
The 'contains' method will return a boolean (true or false), not an integer.

Code:
if ($gameParty.members().contains($gameActors.actor(2))) {
   $gameParty.addActor(3);
   $gamePlayer.refresh();
} else if ($gameParty.members().contains($gameActors.actor(3))) {
   $gameParty.addActor(2);
   $gamePlayer.refresh();
}

I appreciate the reply but it did not work, neither did the following

Code:
if ($gameParty.members().contains($gameActors.actor(2)) === "true") {
    $gameParty.addActor(3);
    $gamePlayer.refresh();
} else if ($gameParty.members().contains($gameActors.actor(3)) === "true") {
    $gameParty.addActor(2);
    $gamePlayer.refresh();
}
Ah, I may have misunderstood what the desired end result was. Perhaps try having two separate if statements.

Code:
if ($gameParty.members().contains($gameActors.actor(2))) {
   $gameParty.addActor(3);
   $gamePlayer.refresh();
}
if ($gameParty.members().contains($gameActors.actor(3))) {
   $gameParty.addActor(2);
   $gamePlayer.refresh();
}
Please don't just say "it doesn't work" - say what DOES happen. Are you getting an error message? Do you have actor 2 or actor 3 in the party? Show us your code. If you run that code and it doesn't give you an error, if you go back to the map is the new party member there? If they are, then the code has worked.

"true" is a text string. That is never going to work.

Ossra's first solution should work, but if you are calling it from a scene other than Scene_Map, then you may need to do more to have it refresh. $gamePlayer.refresh() changes what you see on the map, but your menu screen likely doesn't use that to build its display (or builds what the party was when the scene first loaded). If that's the case, you probably need to show us more of your script so we can see the context.
I appreciate the replies guys, the first code I posted is somewhat half-working. As soon as I equip the weapon Actor 2 is added to the party. Once I un-equip and equip it again though Actor 3 is not added to the party and I'm not sure why.

Ossra's code did not add neither actor to the party, equiping the weapon doesn't seem to do anything.

Edit: The are no other code, this is all there is. I'm using waynee95's onequip plugin.

Edit: After 2 hours of trying different stuff here's what finally did the job :
Code:
if ($gameParty.members().contains($gameActors.actor(2))){
$gameParty.addActor(3);
} else {
$gameParty.addActor(2);
}
$gamePlayer.refresh();

Original thread: https://forums.rpgmakerweb.com/threads/checking-for-and-adding-an-actor-to-party.112802/