Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

split undefined

Hi Experts, I want to avoid undefined message appeared in an alert box since the res[3] is blank. I can't remove the res[3] because it is a client option whether or not he's going to use it. I tried to use a condition like, If (res[3] == "Undefined") but it didn't work. Thank you!

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Go</button>
<input type="text" id="N1" value="Me/and/You"/>

<script>
function myFunction() {
    var msg = document.getElementById('N1').value;
    var res = msg.split("/");
    
    themsgs = res[0] + " " + res[1] + " " + res[2] + " " + res[3 ] ;
    alert(themsgs);
}
</script>

</body>
</html>

Open in new window

SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

Thank you all for providing me the solution but i gave my 400 points to Julian since His solution is working very fine.. More power to all of you!
You are welcome.