Javascript Data Type How to - Split a list of names contained in option tags








Question

We would like to know how to split a list of names contained in option tags.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!-- w w  w .jav a2s .  c o m-->
var myList = "Berry, Barry \
Altimar, Bonnie \
Flopsy, Tonny \
Marildoo, Barby \
Dalibutton, Fling";
var split = myList.replace(/\,/g, "").split(" ");
console.log(split);
}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: