What are the core objects of javascript

青灯夜游
Release: 2023-01-06 11:17:54
Original
3396 people have browsed it

Javascript core objects: 1. Math object; 2. Number object; 2. Boolean object; 4. String object; 5. Array object; 6. Date object; 7. Object object; 8. Function object; 9. RegExp object.

What are the core objects of javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Core objects of javascript

1. Math object

The Math object is used to perform mathematics The operation does not use new to create an instance, but directly uses Math to directly call its properties and methods. For example

var pi_value=Math.PI
var sprt_value=Math.sprt(16);
Copy after login
Math object properties
PropertiesDescription
E Returns the base e of natural numbers (approximately equal to 2.718)
LN2 Returns the natural logarithm of 2 (approximately equal to 0.693)
LN10Returns the natural logarithm of 10 (approximately equal to 2.302)
LOG2EReturns the base 2 pair of e Number (approximately equal to 1.414)
LOG10E Returns the base 10 logarithm of e (approximately equal to 0.434)
PIReturns pi (approximately equal to 3.14159)
SQRT1_2Returns the reciprocal of the square root of 2 (approximately equal to 0.707)
SQRT2Returns the square root of 2 (approximately equal to 1.414)
##log ( x) Returns the natural logarithm of the parameter x (base is e) max (x, y) Returns the two Maximum numbermin(x,y)Returns the minimum of two numberspow(x, y) Returns the y power of parameter xrandom()Returns a random number between 0~1round(x)Round parameter xsin(x)Return the sine value of parameter xsqrt(x)Returns the square root of parameter xtan(x)Returns parameter Tangent
Math object method
MethodDescription
abs(x)Returns the absolute value of parameter x
acos(x)Returns the inverse cosine function of parameter x
asin(x)

Returns parameter x The arcsine value of

atan(x) returns the parameter x as a value between -PI/2 and PI/2 radians The arcsine function
atan2(y,x) returns the angle from the x-axis to the point (x, y) (between -PI/2 and PI /2 radians)
ceil(x)Round up the parameter x. For example, the value of Math.ceil(2.3) is 3
cos(x)Returns the cosine value of parameter x
exp(x)Returns the exponent of e
floor Round the parameters down. For example, the value of Math.ceil(2.3) is 2

2. Number object

var num1=new Nunber(value);
var num2=Nunber(value);
var num3=123;
Copy after login

Number’s object propertyAttributeDescriptionMAX_VALUEThe maximum number that JavaScript can represent MIN_VALUEJavaScript can represent the smallest numberNaNnon-numeric valueNEGATIVE_INFINITYRepresents negative infinity -Infinity, this value is returned when overflowsPOSITIVE_INFINITYRepresents positive infinity nfinity, this value is returned when overflows
Object method of NumberMethodDescriptiontoString() Convert the value into a string, use IRadix to specify the base, the default is decimal toFixed(x)Convert the value into a character String, the number with x digits after the decimal place of the resultConvert the object value into exponential notation, the result There are numbers x after the decimal pointtoPrecosion(x)Format the value into the length given by parameter Returns the original value of a Number object
toExponential(x)

##valueOf

3、Boolean对象

var b=new Boolean(value);
var b=false;
参数只有false、0、null、undefined的情况下会得到false的对象,否则会得到值为true
Copy after login

4、String对象

var x=“JavaScript程序设计”;
Copy after login
String对象的方法
属性描述
anchor()返回str标记的字符串
big()返回str标记的字符串
blink()返回str标记的字符串
bold()返回str标记字符串
fixed()返回str标记字符串
fontcolor(color)返回str标记字符串。由于html5不支持标记,因此一般不用
italics()返回str标记字符串

link(url)

返回str标记的字符串
small()返回str标记字符串
strike()返回str标记字符串
sub()返回str标记字符串
sup()返回str标记字符串
charAt(index)返回指定位置的字符
charCodeAt(index)返回指定位置的Unicode编码
concat(str)连接字符串
indexOf(sSubString,iStarIndex)检索字符串
lastIndexOf(sSubString,iStarIndex)从后向前检索
substr(iStart[iLength])从起始索引号提取字符串中指定目录字符
substring(iStart,iEed)提取字符串中指定的索引号之间的字符
toLowerCase()把字符串转换成小写
toUpperCase()把字符串转换成大写
split(ch)把字符串分割成字符串数组
match(reExpr)找到一个或者多个正则表达式的匹配项
search(reExpr)检索与正则表达式匹配的值
replace(reExpr,sReplaceText)替换与正则表达式匹配的字串

5、Array对象

(1)创建数组

var arrObj=new Array();
var arrObj=new Array(size);
var arrObj=new Array(element0,element2);
Copy after login

(2)数组的length属性

(3)Array对象的方法

Array对象的方法
方法描述
push()向数组末尾添加一个或者更多元素,并返回新的数组长度
unshift()向数组的开头添加一个或者更多元素,并返回新的数组长度
pop()删除并返回数组的最后一个元素
shift()删除并返回数组的第一个元素

splice()

删除元素并向数组添加新的元素
sort()对数组元素进行排序
reverse()颠倒数组中元素的顺序
toString()把数组转换成字符串
join()把数组的所有元素放到字符串中并用指定的分隔符进行分离
concat()连接两个或者更多的数组,并返回结果

slice()

从某个已有的数组返回选定的元素

(4)二维数组的定义与访问

var citye=new Array();
citye[0]=new Array{"sha","上海","SHANGHAI","SH"};
citye[1]=new Array{"HYN","黄岩","HUANGYAN","HY"};
citye为二维数组,使用“数组变量名[子数组索引号][子数组中元素的索引号]”的格式来访问
遍历为双层循环遍历
Copy after login

6、Date对象

(1)Date对象的创建

var dateObj1=new Date();
var dateObj2=new Date(dateval);
var dateObj3=new Date(year,month,date);
Copy after login

(2)Date对象的方法

var d3 =new Date("2019-12-12");
d3.getDate();       //获取当前日期中的日12
d3.getMonth();       //获取月份返回11,月份为(1-11)
Copy after login

7、Object对象

(1)对象的创建

方式一:

var cat1=new Object();
cat1.name="猫咪";
cat2.color="黄色";
cat.eat()=function(){
    alert(this.name+"吃老鼠");
};
Copy after login

方式二:

var cat1=new ();
cat1.name="猫咪";
cat2.color="黄色";
cat.eat()=function(){
    alert(this.name+"吃老鼠");
};
Copy after login

方式三:

var cat1={
cat1.name="猫咪";
cat2.color="黄色";
cat.eat()=function(){
    alert(this.name+"吃老鼠");
    };
}
Copy after login

创建对象实例

var cat2=Object.create(cat1);
Copy after login

8、Function对象

(1)function的创建

funcation sum(x,y){
    return (x+y);
}
Copy after login

(2)第二种格式

function Cat(name,color){
cat1.name=name;
cat2.color=color;
cat.eat()=function(){
    alert(this.name+"吃老鼠");
    };
}
var cat1= new Cat("猫咪","黄色");
cat1.eat();
Copy after login

9、RegExp对象

(1)创建RegExp对象

var regObj=new RegExp("pattern"[,flags])
var regObj=/pattern/{flags}
Copy after login

其中pattern为必选,其对应正则表达式。参数flags是可选项。是标志组合常见的:g代表全局,i忽略大小写。m多行标志

pattern常用字符

(1)普通字符,如汉字、数字、字母 例如 /ab/

(2)转义字符 采用在前面加个\

(3)表达式 []、[^]

(4)特殊字符 ^ $

(5)修饰匹配次数的特殊符号 {n}

(2)RegExp对象的方法

(1)test方法

语法:reg.test(string);
Copy after login
  • reg:是正则表达式对象

  • string:是字符串对象 返回 true或false

(2)exec方法

reg.exec(string);
Copy after login

exec:检索字符串是否存在reg表示模式,存在则返回被找到的值;否则返回空null

【相关推荐:javascript学习教程

The above is the detailed content of What are the core objects of javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!