i have some value stored in array and i wana split them and wana know length of its contains value but when i am running function it is not working
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function(){
var valData= ['songs','video','movie','games','other'];
var valNew=valData.split(',');
for(i=0;i<valNew.length;i++);
alert(valNew.length)
})
</script>
</head>
<body>
<select id="me"></select>
</body>
Split is used to separate a delimited string into an array based upon some delimiter passed into the split function. Your values are already split into an array. Also your for loop syntax is incorrect.
Split Documentation: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split
Corrected code:
$(function(){
var valData= "songs,video,movie,games,other";
var valNew=valData.split(',');
for(var i=0;i<valNew.length;i++){
alert(valNew.length)
}
});
http://jsfiddle.net/tmHea/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With