Whing Dela Cruz
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>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome.
ASKER