Home  >  Article  >  Web Front-end  >  What are the core objects of javascript

What are the core objects of javascript

青灯夜游
青灯夜游Original
2021-06-22 15:26:363402browse

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);
Math object properties
Properties Description
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)
LN10 Returns the natural logarithm of 10 (approximately equal to 2.302)
LOG2E Returns 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)
PI Returns pi (approximately equal to 3.14159)
SQRT1_2 Returns the reciprocal of the square root of 2 (approximately equal to 0.707)
SQRT2 Returns 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
Method Description
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;

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

4、String对象

var x=“JavaScript程序设计”;
String对象的方法
属性 描述
anchor() 返回3499910bf9dac5ae3c52d5ede7383485str5db79b134e9f6b82c0b36e0489ee08ed标记的字符串
big() 返回3d49bde0e0b2e042578ad34140b6c48estrcb47d890eb8c521d3966d2b2263ef112标记的字符串
blink() 返回09e724d88afdbbf2144425ae4c15623cstreb5da82aa206f31e1eaa7796e81653d5标记的字符串
bold() 返回a4b561c25d9afb9ac8dc4d70affff419str0d36329ec37a2cc24d42c7229b69747a标记字符串
fixed() 返回78f983dbc27872ba42409adefe5049d9strd98ca7951c814b9263d12f482df06c69标记字符串
fontcolor(color) 返回464c790c37ed5345fad2893d129831e1stre6e38b3c62e8df885fe2e3986461aa63标记字符串。由于html5不支持4b9ab1a63e76bd6efbc3ef76066e6e2b标记,因此一般不用
italics() 返回5a8028ccc7a7e27417bff9f05adf5932str72ac96585ae54b6ae11f849d2649d9e6标记字符串

link(url)

返回a549acb06b49b192ce2610bbc09c8a00str5db79b134e9f6b82c0b36e0489ee08ed标记的字符串
small() 返回d015d241ae6d34c34210679b5204fe85str7552a991a706bdbcb00625c14ce34064标记字符串
strike() 返回533df51242d4fe18c58d599b7d69a4e4str42c3f6e9e03fa0a8003320368cc30da4标记字符串
sub() 返回b96cac025db4031319c29e1eb68f19d6str270ea406e83044e5b95e23270c35ff95标记字符串
sup() 返回2cdea26b4c3988e37d674b56660962a7str2eb235f530502820017cce1685312d59标记字符串
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);

(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为二维数组,使用“数组变量名[子数组索引号][子数组中元素的索引号]”的格式来访问
遍历为双层循环遍历

6、Date对象

(1)Date对象的创建

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

(2)Date对象的方法

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

7、Object对象

(1)对象的创建

 方式一:

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

方式二:

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

 方式三:

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

 创建对象实例

var cat2=Object.create(cat1);

8、Function对象

  (1)function的创建

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

 (2)第二种格式

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

9、RegExp对象

(1)创建RegExp对象

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

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

   pattern常用字符

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

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

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

       (4)特殊字符        ^ $

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

(2)RegExp对象的方法

(1)test方法

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

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

(2)exec方法

reg.exec(string);

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!

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