Summary of Javascript object attribute methods_javascript skills
数组(Array):系列元素的有序集合
属性:
length:用于获取数组元素的个数,既最大下标加 1
方法:
sort(function):在未指定排序号的情况下,按照元素的字母顺序排列,如果不是字符串类型则转换成字符串,在排序;
reverse():颠倒数组中元素的顺序;
concat(array1,arrayn):用于将N个数组合并到array1数组中;
join(string):用于将数组中元素合并为字符串,string为分隔符,如省略参数,则直接合并,不加分隔;
slice(start,stop):用于返回数组中start到stop中的元素,如果参数为负,则表示倒数start或stop个元素;
toString():将数组所有元素返回一个字符串,其间用逗号分隔;
字符串(string)
属性:
length:用于返回字符串的长度,用法与数组一样;
方法:
anchor():该方法创建如同HTML中的anchor一样的标记,格式 ,通过下列方法访问 string.anchor(chorName)
toUpperCase():将字符串转换成大写;
toLowerCase():将字符串转换成小写;
indexOf(a,b):从第 b 个字符查找字符 a 在字符串中出现的位置并返回,如果 b 省略,则默认从 0 位置查找;
chartAt(i):返回字符串中第 i 个字符;
substring(start,end):返回字符串中从 start - end 之间的全部字符(但是不返回end本身那个字符哦);
sub():将指定的字符串用下标格式显示;
日期(Date):详细演示见
定义方法:
a: var newdt=new Date() -->创建时间对象并赋值为当前时间;
b: var newdt=new Date(milliseconds) --> 创建时间对象,且以GTM的延迟时间来设置对象的值,单位为毫秒;
c:var newdt=new Date(string) -->使用特定的时间字符串为新创建的时间对象赋值,其格式与Date对象的parse方法匹配;
d: var newdt=new Date(年,月,日,小时,分,秒,毫秒) -->按照年,月,日,小时,分,秒,毫秒 的顺序为对象赋值;
方法:获取时间;设置时间;格式转换
A:获取时间
getDate() -----获取当前完整时间;
getYear()------获取当前的年
getMonths()----获取当前的月份
getDay()-------获取当前的日期 天
getHours()-----获取当前的小时
getMinutes()---获取当前的分钟
getSeconds()---获取当前的秒
getTime()------获取当前的时间,单位 秒
getTimeZoneOffset--获取当前的时区偏移信息
b:设置时间
对照上面的获取,把get换成 set 即可,例如 getDate() ---> setDate()
c:转换方法
toGTMString() ------转换成格林威治标准时间表达式的字符串;
toLocaleString()----转换成当地时间表达的字符串
toString()----------把时间转换成字符串
parse---------------从表示时间的字符串中读出时间
UTC-----------------返回从格林威治标准时间到指定时间的差距,单位为 毫秒
Math 数学:
属性:注意,数学对象中的属性是指读的
E (=2.7182) ------自然对数的底(具体意思,我不明白,唉,和数学密切的东西我都不明白,郁闷!)
LN10(=2.30259) ---10的自然对数;
LN2(=0.69315)-----2的自然对数;
PI(=3.1415926)----圆周率
SQRT1_2(=0.7071)--1/2的平方根
SQRT2(=1.4142)----2的平方根
LOG2E(=1.44269)---以2为底,E的对数
LOG10E(=0.43429)--以10为底E的对数
方法: 其实用得上的不多,郁闷,全部弄出来吧
sin(a) ---- 求a的正弦值
cos(a)------求a的余弦值
tan(a)------求a的正切值
asin(a)-----求a的反正弦值
atan(a)-----求a的反余弦值
exp(a)------求a的指数
log(a)------求a的自然对数
Pow(a,i)----求a的i次方(乘方)
round(a)----对a进行四舍五入运算
sqrt(a)-----求a的平方根
abs(a)------求a的绝对值
random()----取随机数
max(a,b)----取较大的数
min(a,b)----取较小的数
注意:函数的参数均是浮点类型,三角函数的参数为弧度值,而不是度
JavaScript的内置函数
escape() 与 unescape() :对字符串进行 编码与解码
eval(字符串):用于执行字符串所代表的运算或语句
例如:var a=0; var str1="a+=a"; eval(str1);
parseInt() 和 parseFloat():将文本框的值转换成整数 或 浮点数
Note: parseInt() does not round the number, but trims the tail
isNaN(): The complete E text is (is not a number). As the name suggests, it is to determine whether the string is a number, such as if(isNaN("天blastpiercing series tutorial"))
Custom objects: There are two methods: initializing objects and objects defining constructors
a: initialization object
For example: Object = {Attribute 1: Value 1; Attribute 2: Value 2; ... Attribute n: Value n}. Note that each attribute value pair is separated by a semicolon;
b: Object defining constructor
For example:
function function name (attribute 1, attribute 2,... attribute N) {
this.Attribute1=attribute value 1;
this.attribute2=attribute value 2;
this.attributen=attribute valuen;
this.methodname1=functionname1;
this.methodname2=functionname2;
}
Note: The method name and function name can have the same name, but before the method calls the function, the function must have been defined, otherwise an error will occur
To create a new instance of a custom function, use the new statement.
Browser Object
Window object: He belongs to the central level, the highest level of all objects. To put it bluntly, without him, you would have nothing to play;
Properties:
closed----------used to determine whether the window is closed;
er----------stores the parent window of the window opened by the () method;
defaultstatus- --The information displayed by default in the status bar;
status----------The information currently displayed in the status bar;
Document, Location, History---very important, will be discussed in detail later, if Don’t want to wait, just look here
Method:
alert(text)-------------pops up a prompt message box
confirm(text)----------confirm message box, the parameter is confirmation Information
prompt(text,default)----pops up the input dialog box, the parameters are prompt information and default value
document object: includes each of the current web page Features, such as title URL background language modification time, etc.
Properties:
title------------Document title
lastModified-----File last modified time
URL--------------Document The corresponding page address
Cookie-----------used to create and obtain Cookie information
bgColor----------the background color of the document
fgColor-- --------The foreground color of the document
location---------Save all page address information of the document
alinkcolor-------The color of the activated link
linkcolor--------The color of the link
vlinkcolor------The color of the viewed link
Method:
write(text)---Write text or labels to the document without line breaks
writeln(text)---Write text or labels to the document with line breaks at the last character
( )----------Open a new document such as ("Address", "Window Name", "Style")
close()---------Close the current document
Location object: Contains all page address information of the current document
Properties:
protocol-----------Communication protocol
host---------------The host name of the WEB server where the page is located
port--- ------------Port number for server communication
pathname----------The path of the document on the server
hash-------- -------Anchor tag information for page jump
searce-------------Search information submitted by the page to the server
hostname------- ----Host name and port number, separated by colon
href---------------Complete URL address
Method:
assign(URL)--------Navigate the page to another address
reload-------------Refresh the page
replace(URL)- ------Use the page with the specified URL to replace the current page
History: This object includes information about previously visited URLs
Attribute: length, returns the number of URLs
The main method is go(n), through which the relative page is loaded

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
