


Basic knowledge for getting started with JavaScript. Friends who want to learn js can refer to_Basic knowledge
stringObject.charAt(index) method: Returns the character at the specified index position.
The stringObject.slice(start,[end]) and stringObject.substring(start,[end]) methods both accept two parameters, which are the starting position and the ending position of the substring, and return the value between the two. string, excluding the string at the terminating position. If the second argument is not specified, it defaults to the length of the string, from the starting position to the end of the string.
【Difference】The main difference between these two methods is the different processing of negative numbers. For slice(), negative parameters are counted from the end of the string, while substring() directly ignores negative numbers and treats them as 0, with 0 as the starting position and positive numbers as the ending position. For example: substring(2,-3) is equivalent to substring(0,2)
stringObject.substr(start,[length]) method: Returns a string starting from the subscript start and with length as the length.
stringObject.indexOf(searchStr,[fromIndex]) method: Returns the string searchStr and searches for the index number that first appears in the stringObject string from fromIndex. If Str is not included in stringObject, -1 is returned. (Search from front to back)
stringObject.lastIndexOf(searchStr,[fromIndex]) method: Return the string searchStr from fromIndex (counting from the end) to search forward for the index number that first appears in the stringObject string. If Str is not included in stringObject, -1 is returned. (Search from back to front)
parseInt(string,[radix]) function can parse a string and return an integer. radix indicates that it needs to be converted into a decimal number (optional), and the default is decimal.
parseFloat(string) function can parse a string and return a floating point number.
Declaration of arrays in JavaScript:
new Array();
new Array(size);
new Array(element0, element0, ..., elementn);
[element0, element0 , ..., elementn];
arrayObject.join([separator]) method returns a string. The string is generated by converting each element of the arrayObject to a string and then concatenating the strings, inserting the separator string between the two elements.
The stringObject.split(separator,[howmany]) method returns an array created by splitting the string stringObject into substrings at the boundaries specified by separator. howmany represents the maximum length of the returned array (optional). stringObject.split("") can split the string stringObject into letters.
arrayObject.reverse() method is used to reverse the order of elements in an array. No return value.
arrayObject.sort() method is used to sort the elements of the array. No return value.
JavaScript definition function
function functionName([arg0,arg1,…,argN])
{
statements
[return[expression]]
}
Accessed with arguments object function parameters. For example, arguments[0] can access the value of the first parameter.
Math.random() method can return a random number between 0 ~ 1.
BOM (Brower Object Model) browser object model
includes: window, document, location, navigator and screen
Commonly used properties and methods of Window objects are:
window.moveBy(dx,dy) : Move the browser window equivalent to the current position horizontally dx pixels to the right and vertically down dy pixels;
window.moveTo(x,y): Move the browser window to (x,y) of the user screen );
window.resizeBy(dw,dh): Relative to the current size of the browser window, increase the width by dw pixels and the height by dy pixels;
window.resizeTo(w,h): The width of the browser window is adjusted to w pixels, and the height is adjusted to h pixels;
window.open([newWindowURL],[newWindowName],[feature1,feature2…]): Open a new window. newWindowName is equivalent to the target attribute of the tag.
windowObject.opener: access the original window that opened the windowObject;
window.close(): close the current window;
window.status="...": set the status bar text;
window.alert( "..."): pops up a prompt message;
window.confirm("..."): pops up a confirmation box;
window.prompt([text],[defaultText]): pops up an input prompt box, defaultText is the default text (Optional);
window.history.go(-1)/window.history.back(): Go back one page;
window.history.go(1)/window.history.forward(): Go forward one page.
The Document object is a property of the Window object and can be accessed through the window.document property.
Common method: document.write(“…”)
The Location object is a property of the Window object and can be accessed through the window.location property.
Commonly used attributes: location.href=URL
Navigator object
Commonly used attributes: navigator.userAgent (Usually the browser’s judgment is done through this attribute.)
Screen object is also a Window object a property.
Commonly used attributes:
screen.availHeight: the screen height that the window can use;
screen.availWidth: the screen width that the window can use;
screen.colorDepth: the number of digits the user can use to represent the color;
screen.height: screen height;
screen.width: screen width.

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 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

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

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

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).
