When we need to get some values in 1000 times, usually we go for a loop and concatenate the strings. But this can be done in a single statement.
<script language = ‘javascript’ >
function Repeats(str, cnt)
{
return alert( (new Array(cnt + 1)).join(str));
}
</script>
By using the above function, you can get a string in ‘n’ number of times like,
Enter the String : <input id = 'txtStr' name = 'txtStr' />
<input type = 'button' onclick = 'Repeats(txtStr.value,1000);' value = ' show' />
To Test
Enter the String :
No comments:
Post a Comment