js reference type
This article shares with you about the reference type of js. Friends in need can take a look.
The value (object) of the reference type is an instance of the reference type,, In js, a reference type is a data structure, usually called a class. es6 seems to have added the concept of class.
1: object is a basic class, and all other types inherit basic behaviors from object.
When js uses the typeof method, Array also returns object. You can use isArray() to determine whether it is an Array type.
2. Array type
Change the original The method of the array is to change the initial array on the prototype chain
push(): Add an array element to the end of the array and return the new array length
pop(): Delete The last item of the array, return to the deleted item
# Shift (): Delete the first item of the array, return to the delete item
United (): Add array elements to the front end of the array, Return the length of the array
reverse(): Reverse the order of the array
sort(): The sorting method of the array, which will call toString() of each item in the array, for Comparison, so it becomes a comparison of strings. It is best to pass it a comparison function
For example:
function compare(value1,value2){ if(value1<value2){ return -1; }else if(value1>value2){ return 1; }else{ return 0; } }
If they are all numerical types, you can pass a simpler one Function
function compare(value1,value2) { return value2-value1; }
concat(): Add the received parameters to the end of the array and return a new array
splice( ): Returns the deleted item, if not, returns an empty array
You can use splice() to delete, add, and add the array
Deletion: splice(0,2) deletes the first two items in the array Item
Add: splice(2,0,"red","green") Insert "red","green" items after Array[2]
Replace: splice(2 ,1,"red") Replace Array[2] with "red"
The above methods will change the following of the original array
The method will not change the original array
slice(0,2): Returns the first two items of the array
The array iteration method every(), filter(),forEach(),map(),some()
Their parameters are all a function
(item,index,array) =>{ }
where every() and some() return true or false
filter() returns the array elements that satisfy the function passed in,
forEach() has no return value,
map() returns the array after calling the function
Merge method: reduce() and reduceRight()
Traverse each item of the array from left to right, reduceRight() from right to left
Accepts two parameters, one function, An initial value (optional)
For example:
let values=[1,2,3,4] let sun=values.reduce((prev,cur,index,arr)=>{ return prev+cur },0)
function type
Function name In fact, it is also a pointer to the function object, which is no different from the variable name pointing to the object.
Change the this pointer inside the function
call(), apply() and bind()
The most important thing about call and apply is the scope in which the extension function runs
For example
window.color="red" let o={color:"blue"} function sayColor() { alert(this.color) } sayColor.call(this)//red sayColor.call(window)//red sayColor.call(o)//blue
bind() will create an instance of the function, and its this value will point to the value that is bound to the bind() function
bind(who), the function this will point to who
Basic packaging type
js creates corresponding basic packaging types for string, num, etc., so some methods can be called
string method
charAt( 1): Returns the character at position "1"
charCodeAt(1): Returns the character code at position "1"
concat() link string, but the most commonly used one is "+"
slice(start,end): intercept the string, end is not passed, defaults to the end position, the parameter is a negative number, converted to (character length + negative number)
substr(start,length): Intercept the string, length is not passed, the default is to the end, the parameter is a negative number and converted to (character length + negative number)
substring(start,afterend): afterend is not passed, the default is to the end, negative number is converted to 0, the smaller number will be used as the starting position
trim(): delete the spaces before and after the string
split(",") split into arrays with ","
split(",",2) takes the first two items of the split array
Math method
Math.ceil(): round up
Math .floor(): Round down
Math.round(): Round
##/ /At the end: The above may not be complete, most of them are things that I don’t have a clear impression of myself
The above is the detailed content of js reference type. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

With the popularity of short video platforms, video matrix account marketing has become an emerging marketing method. By creating and managing multiple accounts on different platforms, businesses and individuals can achieve goals such as brand promotion, fan growth, and product sales. This article will discuss how to effectively use video matrix accounts and introduce different types of video matrix accounts. 1. How to create a video matrix account? To make a good video matrix account, you need to follow the following steps: First, you must clarify what the goal of your video matrix account is, whether it is for brand communication, fan growth or product sales. Having clear goals helps develop strategies accordingly. 2. Choose a platform: Choose an appropriate short video platform based on your target audience. The current mainstream short video platforms include Douyin, Kuaishou, Huoshan Video, etc.

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service
