This article describes how to convert strings and arrays in javascript. If you are interested, refer to the examples in this article to introduce the conversion methods of strings and arrays in javascript, the content is as follows:
Conversion between strings and arrays is v
this series as effective JavaScript 's reading notes. for code encapsulation, the JavaScript There are two ways to do that. The first is to use function, the second is to use the eval () function, and the string argument passed into the function can be a piece of code. when you are hesitant about which method to use, use the function . Because an important disadvantage of using
JavaScript toolkit or API.
Modify JSON data
Just as you can access data with periods and parentheses, you can easily modify the data in the same way:
people.musicians[1].lastName = "Rachmaninov";
After converting a string to a JavaScript Object, you can modify the data in the variable as follows.
Convert back to string
Of course, if you cannot easily convert an object back to the text format mentioned i
The simple point is that string is a character (string) ...And the array is arrays ... Can put numbers ah, character Ah and a series of Dongdong!!!
Last Example:
Copy Code code as follows:
var str = "Liuzhanqi";
document.write (str["Length"]);//equivalence STR.L ength
var str = String.fromCharCode (72, 101, 108, 108, 111, 33);
document.write (str); The integers are encoded as Unicode and are concatenated into strings.
var str
String operations are very frequent and important in js. I can remember it clearly after reading the book, but I don't need it for a while, so I will forget about it. It is hard to remember a poor memory... Today, we will sort out some common operations on strings to help you better understand them. You can also view it in the independent blog: String common operations in javascript summary String object at
Here are some of the more commonly used methods of using strings, strings are arrays of characters, and in JavaScript, strings are immutable: You can access text anywhere in a string, but JavaScript does not provide a way to modify the contents of a known string.Common fea
JS there is no standard multi-line string representation method, but in the template, in order to ensure the readability of the template, we will inevitably use multi-line strings, so there are a variety of way, here with a jade template as an example, simple summary and contrast.The addition of a stringThis is one of the easiest and most commonly used forms, as follows
Copy Code code as follows:
var Tmpl = ' +
'!!! 5 ' +
' HTML ' +
' In
Example of getting started with JavaScript sup method (displaying strings as superscripts), javascriptsup
The sup method returns the supermark string defined using the HTML sup tag attribute. The syntax is as follows:
Copy codeThe Code is as follows:Str_object.sup ()
Tip: This method does not comply with the ECMA standard and is not recommended.
Sup method example:
Copy codeThe Code is as follows:
Run this
As a front-end developer, it is often encountered in Webpage display. The title is too long and the string needs to be intercepted. If CSS is used for implementation, there are various compatibility problems and pitfalls.Let the background program intercept a bit, and a variety of pushes, let the background cut by byte is the same as the old-fashioned background, and finally may only cut the length of the security characters for you, the last look is not good, not neat, still turn back to the CS
objects and DOM objects are encapsulated html elements. They can operate on html element nodes to facilitate programming, but some methods between them cannot be shared, for example, the html () method of the Jquery object cannot be used by the DOM object. The GetElementById () method of the DOM object cannot be used by the Jquery object. Therefore, they can be converted when necessary.
3. Use JavaScript code to convert text string variables into DOM
1. Match methodThe match () method retrieves the specified value within a string, or finds a match for one or more regular expressions.The return value of the match () method is: An array that holds the matching results .2. Replace methodThe replace () method is used to replace other characters with some characters in a string, or to replace a substring that matches a regular expression.The return value of the Replace method is: a new string .3. DescriptionThe parameters of the above 2 methods a
This article mainly introduces some common JavaScript strings and Array Extension functions, and sorts out some simple and frequently-used String and Array functions. For more information, see
Extended functions of String objects:
String. prototype. trim = function () {return this. replace (/^ \ s + | \ s + $/g, "");} String. prototype. ltrim = function () {return this. replace (/^ \ s +/g, "");} String.
Match and replace methods based on strings in JavaScript (detailed description), matchreplace
1. match Method
The match () method can be used to search for a specified value in a string or to find a match between one or more regular expressions.
The Return Value of the match () method is an array of matching results.
2. replace Method
The replace () method is used to replace other characters with some chara
How to transmit strings to the php server through javascript has a page where a specific user can enter the mysql Query command on the page after logging on.
After receiving the command, the php server directly transmits the command string to mysql for execution and then displays the result on this page.
At the beginning, the editable control content was directly transmitted to the server in
1 DOCTYPE HTML>2 HTMLLang= "en">3 Head>4 MetaCharSet= "UTF-8">5 title>Documenttitle>6 Head>7 Body>8 Script>9 //concat (): Connect two strings to return a new string and will not be modifiedTen varstr1= "Hello"; One varstr2= "123"; A varSTR3=Str1.concat (str2); - Console.log (str1); - Console.log (str2); the Console.log (STR3); - - varStr= "I Love my family!"; - Console.log (str); + //Slice (
FastestwaytobuildanHTMLstringPostedinCodeSnippets, JavaScriptbyJamesonMay29th, 2009 Fastest way to build an HTML stringPosted in 'Code Snippets, JavaScript 'by James on May 29th, 2009
Original article: http://james.padolsey.com/javascript/fastest-way-to-build-an-html-string/
The Code is as follows:
Var arr = ['item 1', 'item 2', 'item 3',...],List = '';For (var I = 0, l = arr. length; I List + ='
'+ Arr
There are heredoc ways to define strings in PHP and Python:
Php:
Copy Code code as follows:
$sql =SELECT *
From pages
where Pagename= ' $PN '
EOD;
Python:
Copy Code code as follows:
Print "" "
This is a example of a string in the Heredoc syntax.
This text can span multiple lines
"""
JS concatenation of a large number of strings no heredoc style oper
JSON (JavaScriptObjectNotation) is a simple data format, which is lighter than xml. the following section describes a small problem of Eval parsing JSON strings in JS, for more information about JSON, see the introduction to JSON. As we all know, advanced browsers can use JSON. parse () API to parse a JSON string into JSON data. we can use the eval () function if it is slightly inappropriate.
JSON (JavaScript
JSON (JavaScriptObjectNotation) is a simple data format, which is lighter than xml. The following section describes a small problem of Eval parsing JSON strings in JS, for more information about JSON, see the Introduction to JSON. As we all know, advanced browsers can use JSON. parse () API to parse a JSON string into JSON data. We can use the eval () function if it is slightly inappropriate.
JSON (JavaScript
If you are using the RESTful API now and you need to build a response to a JSON format string through a Web project, this article will help you use JavaScript to create a JSON format string. This is very useful and we will convert the data objects to JSON format via the jquery plugin $.tojson.
using JavaScript to build JSON format strings
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.