In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the methods of JavaScript built-in objects". In daily operation, I believe many people have doubts about the methods of JavaScript built-in objects. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what are the methods of JavaScript built-in objects?" Next, please follow the editor to study!
1. Built-in object
There are three kinds of objects in JavaScript: custom objects, built-in objects, and browser objects.
The first two objects are the basic content of JS, and the third browser object of ECMAScript; is unique to our JS.
Built-in objects are objects that come with the JS language, which are available to developers and provide some common or most basic and necessary functions (properties and methods).
The biggest advantage of built-in objects is that they help us develop quickly.
JavaScript provides several built-in objects: Math, Date, Array, String, and so on.
2. Built-in object: Math object 2.1 Math Overview
The Math object is not a constructor, it has properties and methods of mathematical constants and functions. Math-related operations (absolute, rounding, maximum, etc.) can use members of the Math.
Math.PI / / pi Math.floor () / / rounding down Math.ceil () / / rounding up Math.round () / / rounding up the nearest round note-3.5.The result is-3Math.abs () / / absolute Math.max () / Math.min () / / find the maximum and minimum values
Note: the above method must be in parentheses.
Case: encapsulating one's own mathematical object
Use objects to encapsulate your own mathematical objects with PI, maximum and minimum values.
/ / Mathematical objects using objects to encapsulate themselves have PI maximum and minimum values var myMath = {PI: 3.141592653, max: function () {var max = arguments [0]; for (var I = 1; I)
< arguments.length; i++) { if (arguments[i] >Max) {max = arguments [I];}} return max;}, min: function () {var min = arguments [0]; for (var I = 1; I < arguments.length) If (arguments [I] < min) {min = arguments [I];}} return min;}} console.log (myMath.PI); console.log (myMath.max (1,9,20,3,21,54,211,567,80)) Console.log (myMath.min (1,0,90,-10,82)); 2.2 Random number method random ()
The random () method can randomly return a decimal with a value range of [0random 1), left closed and right open 0 max) {max = o [k]; ch = k;}} console.log ('the most frequent characters are' + ch, 'the number of times is:' + max)
(3) string operation method
/ / string manipulation method (key) / / 1.concat ('string 1', 'string 2', etc.) Concatenate two or more strings, equivalent to + var str = 'andy';console.log (str.concat (' red')); / / "andyred" / / 2.substr ('start position of interception', 'intercept a few characters') to intercept the string var str1 = 'Reform Spring Wind blows all over the ground'; console.log (str1.substr (2,2)); / / "Chunfeng" the first 2 is the number of strings taken by the index number and the second 2 is the number of strings taken
(4) replace () method and split () method
The replace () method is used to replace some characters in a string with other characters.
The format is as follows:
Replace (string to be replaced, string to be replaced); / / 3.replace (string to be replaced, string to be replaced) Replacement character it will only replace the first character var str3 = 'andyandy';console.log (str3.replace (' averse,'b')); / / "bndyandy" / / there is a string 'abcoefoxyozzopp' that requires that all' o' be replaced with * var str4 = 'abcoefoxyozzopp';while (str4.indexOf (' o')! =-1) {str4 = str4.replace ('ovoid,' *');} console.log (str4) / / "abc*ef*xy*zz*pp"
The split () method is used to split strings, which can be split into arrays. After the sharding is complete, a new array is returned.
The / / 4.split () method is used to split strings, which can be split into arrays. After the sharding is complete, a new array is returned. / / split ('delimiter') convert characters to arrays We learned earlier that join converts arrays to strings var str5 = 'red, pink, blue'; console.log (str5.split (',')); / / ["red", "pink", "blue"] var str6 = 'red&pink&blue'; console.log (str6.split (' &')); / / ["red", "pink", "blue"]
Other methods:
ToUpperCase () / / convert capitalization
ToLowerCase () / / convert lowercase
At this point, the study of "what are the methods of JavaScript built-in objects" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.