//split () splits the string into a string array according to the specified rules, and returns the array (method of string to array) //Split String varBSTR = "Www.baidu.con"; vararr1 = Bstr.split (");//do not specify any separators, each of them will be splitConsole.log (ARR1);//W "," W "," W ",". "," B "," A "," I "," D "," U ",". "," C "," O "," n " varARR2 = Bstr.split (".");//use the "." As separatorsConsole.log (ARR2);//["www", "Baidu", "con"] varARR3 = Bstr.split ('. ', 2);//use the "." As a delimiter, and specifies the maximum length of the returned arrayConsole.log (ARR3);//["www", "Baidu"] //Complex String Segmentation: Extracts the names and ages of the following three people, generating an array of objects varDatastr = "Editorialcommittee,29& Chu Yaven,32& Baiyu, 28"; //first split: separate three-person information varPeoplearr = Datastr.split (' & ')); Console.log (Peoplearr); varObjarr = []; //iterate through the resulting array for(IinchPeoplearr) { //Console.log (Peoplearr[i]); //splits the information for each index in the number again and declares an array variable to receive varPeopledata = Peoplearr[i].tostring (). Split (', '); //Console.log ("Peopledata:" +peopledata); //remove data from an array and store it in an object varobj ={name:peopledata[0], age:peopledata[1] } //console.log ("obj:", obj); //to store an object in an array of objectsObjarr.push (obj); } console.log (Objarr); //saves the data as a string in a local varObjstr =json.stringify (Objarr); Localstorage.plpdata= Objstr;//localstorage data storage with no time limit
JS implements a string cut and converts it into an object format saved to the local