array items that meet certain criteria.3.map ()Map () is an array that runs the given function for each item in the array, returning the result of each function call. Each item of this array is the result of running an incoming function on the corresponding item in the original data, for example:var numbers=[1,2,3,4,5,4,3,2,1];var mapresult=numbers.map (function (Item,index,array) {return item*2;});alert (
Recently, you need to store a data stored in the HashMap key and value to the database. The concrete structure is roughly mapinsert id= "Savematchresult" > INSERT into Sp4_acl_so (acl_id, so_uuid__proc_def_id) foreach
collection= "Acldevicemap.keys" index= "index" item= "item" separator= "UNION All" > foreach collection= "acldevicemap[item" "Index=" Index_set "item=" set "separator=" UNION All "> SELEC
var array = [23,48,66,2]; ForEach: Loops, iterates through an array, no return value. Similar to For Loop Array.foreach (function (value, index, array) { console.log (value); return value * value;}); Map : The map means that the map returns a new array with a return value; Filterarr: Returns a new object var Maparr
. Map (FN) method
var a=[2, 4, 6];
a.map(function(d, i, arr){
return {x:i, y:d*i, z:arr};
});
Output Result:
[{x:0, y:0, z:[2, 4, 6]},
{x:1, y:4, z:[2, 4, 6]},
{x:2, y:12, z:[2, 4, 6]}]
the D in the callback function is the value of the traversal array, and I is the index of the array, and the entire array is passed in the third parameter .map casts the origin
The newly added API interface forEach map filter in Array in ES5 some every indexOf lastIndexOf reduce reduceRight
var array = [23,48,66,2];
ForEach: loop, traversing array; no return value. Similar to for Loop
array.forEach(function( value, index, array ) { console.log(value); return value * value;} );
Map: in
vararr = [n/a];//[] is the new Array (All-in-one) syntax sugar (shorthand) varobj = {' name ': 2, ' Age ': 3};//{} is a shorthand for new Object () //var obj2 = new Object (); //obj2.name=2; //obj2.age=3; //ForEach facilitates all elements Arr.foreach (function(item,index) {//iterate over all elements of an arrayConsole.log (item)//1 2 3 })//Every determine if all elements meet all conditions varPD = Arr.every (function(item,index) {//used to determi
);//Index is 0index = Array.lastindexof (2,-2);//Index is 0index = Array.lastindexof (2,-1);//Index is 3//Results://[2, 5, 9, 2].lastindexof (2): 3//[2, 5, 9, 2].lastindexof (7):-1//[2, 5, 9, 2].lastindexof (2, 3): 3//[2, 5, 9, 2].lastindexof (2, 2): 0//[2, 5, 9, 2].lastindexof (2,-2): 0//[2, 5, 9, 2].lastindexof (2,-1): 3indexOf ():function as with LastIndexOf (), the search is in the forward direction // Find the element that meets the criteria: var array = [2, 5, 9]; var index = array.indexof
callback functionCharacteristicsThe map method invokes the callback function sequentially for each element in the original array . callback The return value (including undefined) after each execution is combined to form a new array. the callback function is only called on the indexed index, and those indexes that have never been assigned a value or deleted by using delete are not called. CaseAdd 2 to each item in the arrayvar arr = [' A ', ' B ', ' C
The 1.forEach method is used to invoke each element of an array and pass the element to a callback function.Array.foreach (function (Currentvalue,index,arr), thisvalue);1.currentValue must be. The current element.2.index is optional. The index value of the current element.3.arr is optional. The array object that corresponds to the current element4.thisValue is optional. The value passed to the function is generally used with this value, and if this ar
JS added several methods to the array in 1.6 for the map (), filter (), some (), every (), ForEach (), that is, there are so many methods.It is not clear that we are beginning to touch these, so we have a record here to deepen the impact. I mainly from two angles to understand and remember, one is the use of the API, one is the internal implementation.function briefMap (): Returns a new array with each elem
ES5 new Common Array methodLet arr = [1, 2, 3, 2, 1];A ForEach = to iterate over an arrayArr.foreach ((v, i) = = {Console.log (v, i);});Two map = Use an array to get a new array using a rule mapLet Maparr = Arr.map ((v, i) = = {Return v * v;});Arr.map ((v, i) = v * v); If there is only one sentence, you can omit the curly brace and returnConsole.log (Maparr); [1, 4, 9, 4, 1]Three filter = to find the elemen
JS added several methods to the array in 1.6 for the map (), filter (), some (), every (), ForEach (), that is, there are so many methods.It is not clear that we are beginning to touch these, so we have a record here to deepen the impact. I mainly from two angles to understand and remember, one is the use of the API, one is the internal implementation.function briefMap (): Returns a new array with each elem
specified function (callback), until this function returns false, and if this element is found, every returns falseif the callback function returns true after each element is executed. Every will return true. It executes the specified function only for non-empty elements in the array, no assignment, or the deleted element is ignoredTests whether all array elements are greater than or equal to 10:function Isbigenough (element, index, array) { ForEach
This is a small feature in the company's projects over the past two days. Some jstl labels have been used, but they have not been used before. Now they are basically implemented.
1. The most common use of jstl is if, foreach, and out.
VaR items varstatus begin end step, which are frequently used
Custom jstl labels
Some features may need to be implemented by ourselves during development, but are the standards provided? We can write
For exa
The value of the map is taken out of the JSP and a check box is generated based on the key value;The package to use@ Page Import="Com.hebrf.dbmanage.DBManage"%>@ Page Import="com.hebrf.dbmanage.DBFactory"%>@page Import="java.util.List"%>@page Import="Java.util.Map"%>@ taglib Prefix="C"URI="Http://java.sun.com/jsp/jstl/core" %> Find a map by databaseDbmanage db = Dbfactory.getdbmanage (); List lis = Db.ge
;};Array.prototype.filter =function(Fun/*, thisp*/) {var len =This.length;if (typeof Fun! ="Function")ThrowNewTypeError ();var res =NewArray ();var thisp =arguments[1];for (var i =0; i if (iInchThis) {var val =This[i];In case fun mutates thisif (Fun.call (Thisp, Val, I,This)) Res.push (Val); } }return res;};Array.prototype.some =function(Fun/*, thisp*/) {var len =This.length;if (typeof Fun! ="Function")ThrowNewTypeError ();var thisp =arguments[1];for (var i =0; i if (iInchThis fun.call (Thisp,T
123 45678 + - + A at - - - - - in - to + - the the the theRelated articles:Http://www.cnblogs.com/mabelstyle/archive/2013/02/19/2917260.htmlJS native foreach, map and jquery each, $.each difference
Every:Each item in an array runs the given function, and returns TRUE if the function returns true for each item.var number = [1,2,3,4,5,6]; var result = Number.every (function(item,index,array) { return (item > 0 )}) Console.log (result) //trueFor every (), the incoming function must return true for each entry, which returns TRUE, otherwise he returns false;SomeReturns True if the function returns true for any of the given functions in an array.var number = [1,2,3,4,5,6]; var result = Numb
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.