CopyCode The Code is as follows: var foreach = (function (){
// Array and pseudo array Traversal
VaR _ array_foreach = function (array, block, context ){
If (array = NULL) return;
// Special processing of string
If (typeof array = 'string '){
Array = array. Split ('');
}
VaR I = 0, length = array. length;
For (; I };
// Object Traversal
VaR _ function_foreach = function (object, block, context ){
For (var key in object ){
// Only traverse local proper
1. js array looping.
Array loop variables, the first thought of is for (VAR I = 0; I
In addition, you can also use a relatively simple foreach method.
2. foreach function.
Both the array type of Firefox and chrome have foreach functions. Use:
However, the above Code cannot work normally in IE.
Because the array of IE does not have this method
alert(Array.prot
The foreach extension method of the JavaScript arrays array, foreach, is one of the most commonly used array extension methods, equivalent to a parameterized loop array, which simply applies the incoming function on each element of the array, which also means that only the elements that exist are accessed and processed.If we replace the handler with Console.log,
JavaScript is a literal-translation scripting language, which is a dynamic type, a weak type, a prototype-based language, and a built-in support type. Its interpreter, known as the JavaScript engine, is widely used as a scripting language for the client, and is used in HTML (an application under the standard Universal markup Language) to add dynamic functionality to an HTML web Page.JavaScript has been in e
element, and the array to be traversed. if there is only one parameter, this parameter is the current array element.
Var data = [1, 2, 3, 4, 5]; // calculate the sum of the array and var sum = 0; data. forEach (function (value) {sum + = value ;}); // The value here represents data [0 ~ 4]; console. log (sum) // 15 // add 1data to each array element. forEach (function (v, I, a) {a [I] = v + 1 ;}) // v repr
The ForEach () function iterates through the array from beginning to end. There are three parameters: the array element , the index of the element , the array itself (if a parameter is an array element, that is, the value of the array).1 vardata=[1,2,3,4,5,6];2 varSum=0;3Data.foreach (function(v) {//where V is the value of the array 1234564sum+=v;})5document.write (sum+ "6");//printed out is7Data.foreach (function(O,P,Q) {//corresponding to: array ele
mycars = new Array ()Mycars [0] = "Saab"Mycars [1] = "Volvo"Mycars [2] = "BMW" For (var x in mycars ){Console. log (x );}
Console output:
012
There are two major differences between java's foreach loop. First, the java foreach loop does not enumerate the attributes of a java object. Second, when java's foreach cyclically enumerates an array or any Object impl
Today, colleagues said JS front-end for the efficiency of the high, I do not believe, because I remember that the efficiency of foreach in PHP is more efficient than for, and then I did a test, as follows:Under Chromejquery each:60Native loop:22HTML5 foreach:151Under the IE11jquery each:65Native loop:27HTML5 foreach:98JS's for function is still more efficient tha
This article describes how to use Array. prototype. forEach (). It is helpful for you to learn javascript. The Array. prototype. forEach () method enables each item of the Array to execute a given function. -MDN
Suppose there is a scenario where you get such an array
[{Symbol: "XFX", price: 240.22, volume: 23432 },{Symbol: "TNZ", price: 332.19, volume: 234 },{Sy
When we were a child, we used our own hands to play the puzzle game. Today, we will study and use javascript to make puzzles. If you are interested, I hope this article will help you. When you were a child, we used to play the puzzle game, and we used our own hands to work on it. Today we are going to study how to use javascript For puzzles. It is also a puzzle, but it is much more complicated to use js puz
When we were a child, we used our own hands to play the puzzle game. Today we are going to study how to use javascript For puzzles. It is also a puzzle, but it is much more complicated to use js puzzles than to use hand puzzles, so I will optimize it into an engine in the future.
I. Preface
The above is a piece of introduction, which is easy to talk about. players familiar with the "Three Kingdoms Cao Zhuan Chuan" know that the
After a outsourcing, let me do the map system. Using C # nested JavaScript programming for Hybird applications, framework memory is based on WinForm, invoking control Webbrowser,webbrowser interpretation, rendering HTML files, JavaScript scripts. Map using the Baidu Map API,
(1) Internal scale
This example shows how to add a scale map. Can be added to a map, or a scale at a user-specified location. The following code fragment shows the default scale shown in the lower-left corner of the map.
var scalebar=new esri.dijit.Scalebar ({Map:map});
You can modify the map for that location by setti
1. First get Baidu JavaScript APIFirst open the http://api.map.baidu.com/api?v=1.3 as shown in the browserWhere http://api.map.baidu.com/getscript?v=1.3key=services=t=20121108061854 this link is the API file we're looking for,Also open it in the browser and save it as "Apiv1.3.min.js"and Baidu map must be some of the controls, cursors, logos and other pictures are also downloaded down2. Modify the "apiv1.3.
HTML part of the codeCSS Part code. maxwidth{width:1200px;margin:0px Auto;} /* Map */ . Map-box{background-color: #fff; width:750px;height:538px;border:1px solid #eee;} #allmap {width:730px;height:518px;margin:10px;} Span. Bmap_marker label. bmaplabel{border:1px solid #000;border-radius:3px;} /* Map End */JS Section Code As follows: Write the
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.