Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript base object


May 29, 2021 Article blog


Table of contents


JavaScript's basic objects are critical, and the second step in grammar is the object.

The base object

1、function

The arguments passed in by the function object are placed in the argumentments array, and you only need to call the arguments array to get all the parameters

//创建方式1
function fun1(a,b){
	alert(a+b);
	}
//创建方式2
var fun2=function(a,b){
	alert()a+b);
	}
//调用方式
fun1(34);

alert(fun1.length);//显示形参的个数

2, Array object

Array objects vary in length and content types.

//创建方式1
var arr=new Array(元素列表:123);
//创建方式2
var arr=new Array(元素长度:2);//注意括号中只有一个元素时代表数组长度
//创建方式3
var arr=[元素列表:1234];

3, Date object

var date =new Date();
document.write((data.toLocalString()+"<br>")//转换成本地时间格式
document.write((data.getTime()+"<br>")//转换成从1970年0时0分至今的毫秒数

4, Math object

document.write((Math.PI+"<br>")//π
document.write((Math.random()+"<br>")//随机数
document.write((Math.round(3.14)+"<br>")//四舍五入
document.write((Math.floor(3.14)+"<br>")//向上取整
document.write((Math.ceil(3.14)+"<br>")//向下取整

5, RegExp (regular expression) object

Single-character:

 [a]	[abc]    [a-f]  
 /d :单个数字字符
 /w:单个单词字符[a-zA-Z0-9]

Measure word symbols

  ?:出现01次
  *:出现0或多次
  +:出现至少一次
  {m,n}:出现次数在m与n之间,缺省表示至多或至少的意思

End and start tags

  ^:开始标记
  $:结束标记
//创建方式1
var reg=new RegExp("正则表达式:\\w{6,12}")//注意需要\\来表达\
//创建方式2
var reg=/正则表达式/

The Text method is used to determine whether an object can satisfy a regular expression

6, Global object

encodeURI(str) //url编码
decodeURI(str)//uri解码
encodeURIComponent(str) //url编码,编码的字符更多
decodeURIComponent(str)//uri解码
parseInt(str) //逐一判断每一个字符是否为数字,如果不是数字则停止判断,并将前面部分转化成number
isNaN() //只有这个可以判断NaN,因为NaN参与的==均返回false;
eval() //将字符串代码作为脚本代码执行

That's all the little editor brings you about the JavaScript basic object