filter ():
Grammar:
var filteredArray = array.filter(callback[, thisObject]); |
Parameter description:
Callback: The callback function to execute for each array element.
Thisobject: The This object that is defined when the callback function is executed.
Filter out the array elements less than 10://code: function Isbigenough (element, index, array) {
Function Description:
Each element in an array is executed once for the specified function (callback), and a new array is created, which is the original array element whose return value is true when all the callback functions are executed. It executes the specified function only for non-empty elements in the array, no assignment or deleted elements are ignored, and the newly created array does not contain the elements.
The callback function can have three parameters: the current element, the index of the current element, and the current array object.
If the parameter thisobject is passed in, it will be treated as the this object inside the callback function (callback), and if it is not passed or null, the global object will be used.
Filter does not change the original array, remember: Only the array elements passed in before the callback function executes, the elements that are added after the callback function begins execution are ignored , and the elements of the array are deleted or changed when the callback function begins execution to the last element. When the callback function accesses the element, the deleted element is ignored.
map ():
Converts all array elements to uppercase: var strings = ["Hello", "array", "World"];function makeuppercase (v) {
some ():
Each element in an array executes the specified function once (callback) until this function returns true, and if this element is found, some returns trueif the callback function returns false after each element is executed, some will return false. It executes the specified function only for non-empty elements in the array, no assignment, or the deleted element is ignored.
Checks if there is an array element greater than or equal to 10:function Isbigenough (element, index, array) {
every ():
Each element in the array executes once the 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 ignored
Tests whether all array elements are greater than or equal to 10:function Isbigenough (element, index, array) {
ForEach ():
Print Array contents: function Printelt (element, index, array) { Document.writeln ("[" + Index + "] is" + element + "<br/>") ;} [2, 5, 9].foreach (printelt);//prints://[0] is 2//[1] was 5//[2] is 9//result://[0] is 2//[1] was 5//[2] is 9
lastIndexOf ():Grammar
var index = Array.lastindexof (searchelement[, FromIndex]);
Parameter description
Searchelement: The element to search for
FromIndex: The location at which to start the search, which defaults to the length of the array, in which case all the element elements are searched. the search is in the opposite direction.
Function description
Compares the absolute consistency (= = =) of each element of the searchelement and array, and returns the index of the current element when there are elements that meet the criteria. If not found, return-1 directly.
indexOf ():
function as with LastIndexOf (), the search is in the forward direction
Js array--filter (), map (), some (), every (), ForEach (), LastIndexOf (), IndexOf ()