4. JS commonly used functions

tags: js  javascript

1. Array

1. reduce()

  • Definition: Reduce () method receives a function as a cumulator. Each value (from left to right) in the array is reduced, and the final calculation is a value.
  • grammar:array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
  • Example:
    Calculate the sum of the addition of the array element: (Result: 125)
var numbers = [65, 44, 12, 4];
 
function getSum(total, num) {
    return total + num;
}
function myFunction(item) {
    document.getElementById("demo").innerHTML = numbers.reduce(getSum);
}

Intelligent Recommendation

Js package commonly used functions

Encapsulate commonly used js functions Get the request parameters in the current page url Splice url and parameters (json) Vue http request (get) Native http request (get) Native http request (jsonp) ...

Commonly used js functions in work

yh-js-Kit git: github.com/Michaelhooo… AboutCookie setCookie(name, value) getCookie(name) delCookie(name) arrayFlattening steamroller arraySortByKey arraySortByKey changeDigitalDisplay formatTh...

Js commonly used functions included

First, the function page loads addLoadEvent () Since window.onload can only bind a command, when a plurality of instructions is bound, the last that will only function is actually carried out. In this...

More Recommendation

js / as some of the commonly used functions

table of Contents Array/Object An array of selected elements to retain Object of the array of key String String from the start position reserved Precise decimal digits, rounding Array/Object An array ...

Native JS commonly used functions

As a function of binding parameters Description: The function passed as a parameter, using the closure as a function of binding parameters to be passed. Scenario: You can not specify parameters for th...

JS commonly used tool functions

Deep clone objects Date format Get the file extension Detect empty objects Randomly generate n ~ m character strings Randomly generate colors...

Some commonly used functions of js

Functions commonly used in js development String to number String to array Merge object properties (useful in configuration data merge)...

Math commonly used functions in js

Math object There are many built-in objects in JS. Among them, the Math object encapsulates many commonly used mathematical functions. Math.random This method is used to generate a random number 0~1 c...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top