specifying javascript string split size -


i want separete text split function this. array items should 3 charecters.

var text = "abcdef"; var splitted = ["abc", "def"]  var text = "abcdefg"; var splitted = ["a", "bcd", "efg"]  var text = "abcdefgk"; var splitted = ["ab", "cde", "fgk"] 

text split last first.

var size = 3; //specify size here var str = "abcdefgk" //the string want split  var = str.length % 3; // modulo gets remaining part var result = [str.substring(0,i)]; //create array first part  //for rest, iterate on str , add chunks of length size for(; < str.length; i+=size){     result.push(str.substring(i, i+size))  } alert(result) //display result 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -