To improve the performance of our programs by using the group storage algorithm, we can create and execute regular expressions more efficiently. It would be better to create regular expressions literally. Obviously, sometimes we have to use the large-consumption creation method new RegExp (). For example, regular expressions are used in syntax highlighting and formatting, the more patten you need, the longer the time it takes. Firefox seems to have is
string, mainly used on the Date objectvar a = new Date ();document.write (A.tostring ()); Sat 8 17:28:36 utc+0800 2009document.write (A.tolocalestring ()); August 8, 2009 17:28:36document.write (A.tolocaledatestring ()); August 8, 2009The difference is that toString () returns the standard format, tolocalestring () returns the local format full date (in Control Panel >> Regional and Language Options, by modifying [time] and [Long Date] format), toloc
When learning underscore.js array-related APIs, I encountered the sparse array, which has not been touched before.Here you learn what are sparse arrays and dense arrays.What is a dense array? In the Java and C languages, an array is a contiguous storage space with a fixed le
Array (3 );
Create an array with a length of 3
Var arr = new Array ("a", "B", "c ");
Create an array containing three elements, subscript 0, 1, 2
The following is an incorrect method to create an array:
Var arr = {1, 2, 3 };
Var arr = [,];
2. Add/set
values returned by the function are automatically passed to the next item as the first argument
string of array elements
Arrayobj.join (separator);
Returns a string that connects each element value of an array, separated by a separator in the middle.
toLocaleString, toString, valueof: Can be seen as a special use of join, not commonly used
Tosource () returns the source code for this object
ToString
An array is a linear memory allocated. It uses Integers to calculate the offset and access the elements. Arrays are fast data structures, but unfortunately Javascript does not have the same data structure as this array. The array of Javascript is actually an object. It conve
ArticleDirectory
Array object Method
Attribute of an array object
An array is a linear memory allocated. It uses Integers to calculate the offset and access the elements. Arrays are fast data structures, but unfortunately JavaScript does not have the same data structure as this
performance.
Language level aspects
Cycle
Loops are a very common control structure, most things depend on it to do it, in JavaScript we can use for (;;), while (), for (in) three loops, in fact, in these three loops for (in) is very inefficient because he needs to query the hash key, As long as you can, you should try to use less. for (;;) The performance of the while loop should be the same as the basic (usually used) equivalent.
In fact, the u
The JavaScript array is essentially an object that converts the subscript of an array into a string and uses it as a property, so it is significantly slower than a real array, but it can be used more easily.
Change oneself pop,push,reverse,shift,sort,splice,unshift, do not change oneself concat,join,slice,indexof,last
"document". Note that setting (or ignoring) Xhr.responsetype = ' defaults to set the response to ' text '. There is one such correspondence here:Request Response text domstringarraybuffer arraybufferblob blobdocument DocumentGive me a chestnut:var xhr = new XMLHttpRequest (); Xhr.open (' GET ', '/path/to/image.png ', true); Xhr.responsetype = ' arraybuffer '; xhr.onload = function (e) { //This.response = = Uint8array.buffer var uint8array = new
foreach () method is an upgrade notation for a for loop. I recommend that you try to use the foreach () method if you can choose.There is an easily overlooked problem with the FOR loop: variables declared in the For loop (such as Var i=0 in the previous example) are not local variables in the for loop, but local variables within the scope of the For loop. in the example above, the variable var i = 0 decla
This article mainly introduces the Javascript array method in detail, which is very comprehensive and detailed. if you need it, you can study it and hope it will help you in JavaScript, arrays can be created using the Array constructor or using [] for quick creation. this is the preferred method. An
object.
Length
Sets or returns the number of elements in the array.
Prototype
gives you the ability to add properties and methods to an object.
Array Object method
Method
Description
Concat ()
Joins two or more arrays and returns the result.
Join ()
Put all the elements of the
based on the many tests I have done for JavaScript before, hoping to help you improve your JavaScript script performance.Language hierarchyLoopLoop is a commonly used control structure. Most things are completed by it. in JavaScript, we can use for (;), while (), for (in) in fact, the efficiency of for (in) in these three loops is very poor, because it needs to
implementation using reference types, and the results are the same;That is, the String type behaves as a basic type;The following example illustrates the difference between the base type and the reference type:*/
var a = 3.14;var B = A;A = 4;Console.log (A, b); 4, 3.14;
var a = [1, 2, 3];var B = A;A[0] = 99;Console.log (A, b); Same [99, 2, 3];
Arrays are reference types, and variables A and B point to the same memory address;The variable holds the actual value of the base type an
Are you familiar with operations on Javascript arrays? Here, I would like to share with you a brief introduction, including creating, adding, deleting, reading, and common methods and attributes of JavaScript arrays, I believe this article will surely help you gain some benefits.
Javascript array and operations
This ar
original array value at the end of the temporary array (temary[temary.length]=ary[i])7. reverses the contents of an arrayA) REverse ()I. Direct reversalIi. returning the result as a reversed arrayb) Custom8. array sorted by character ASCII code Sort()a) Ary.sort ([Funname])b) when sort() has no parameters,i. according to ASCII values are sorted in ascending ord
Splice ()
Deletes the element and adds a new element to the array.
Tosource ()
Returns the source code for the object.
ToString ()
Converts the array to a string and returns the result.
toLocaleString ()
Converts the array to a local
In JavaScript, arrays can be created using the array constructor, or created quickly using [], which is also the preferred method. An array is a prototype that inherits from object, and he has no special return value for TypeOf, and he only returns ' object '.
1. Array.prototype.slice methodThe slice method of an array
Arrays are an important data storage type in javascript. Next I will summarize how to create, define, delete, and modify an array length instance in js.
Define an array
The Code is as follows:
Copy code
Var a = new Array ("a", "B", "c ");Method 1.Var
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.