文章目录
数组
- 修改数组
 - arr.length 获得数组长度
 - arr.pop() 数组末位删除
 - arr.push() 数组末位添加
 - arr.shift() 数组头部删除
 - arr.unshift() 数组头部添加
 - 数组和字符串之间转换
 
字符串
- ➕字符串拼接
 - str.length 字符串长度
 - str.indexOf(searchValue, fromIndex); 在字符串中查找子字符串
 - slice(strat,end) 字符串提取
 - toLowerCase() 和 toUpperCase() 字符串并将所有字符分别转换为小写或大写
 - str.replace() 字符串替换
 
类型转换
- String() 转换为字符串类型
 - Number()转换为数值类型
 - parseInt() 转化为整型
 - paereFloat() 转化为浮点型
 - 执行减0操作
 
var n = "10";
var m = n - 0;
m; // returns 10
 
若该字符串不是纯粹的数字字符串,那么它执行减 0 操作后,虽然变成了一个数字类型,但是返回值为 NaN。
- Boolean()转化为布尔类型
 
常用内置对象
Array对象
- Array对象的常用属性:length
 - Array对象的常用方法:
 
- concat() 连接两个或多个数组,并返回结果
 - join() 将数组转化为字符串
 - pop() 末尾删除
 - push() 末尾添加
 - reverse() 颠倒顺序
 - shift() 头部删除
 - unshift() 头部添加
 - slice() 从已有的数组返回选定的元素
 
- splice() 删除或替换当前数组的某些项目
 
- sort()
 - toString()
 
String对象
- String对象的常用属性:length
 - String对象的常用方法:
 
- charAt()
 - charCodeAt()
 - concat()
 - slice()
 - indexOf()
 - toString()
 - toLowerCase()
 - toUpperCase()
 - replace()
 - split()
 
Date对象
Date对象方法:
- Date():返回当日的日期和时间(输出的是中国标准时间)。
 - getDate():从 Date 对象返回一个月中的某一天 (1 ~ 31)。
 - getDay():从 Date 对象返回一周中的某一天 (0 ~ 6)。
 - getMonth():从 Date 对象返回月份 (0 ~ 11)。
 - getFullYear():从 Date 对象以四位数字返回年份。
 - getHours():返回 Date 对象的小时 (0 ~ 23)。
 - getMinutes():返回 Date 对象的分钟 (0 ~ 59)。
 - getSeconds():返回 Date 对象的秒数 (0 ~ 59)。
 - getMilliseconds():返回 Date 对象的毫秒(0 ~ 999)。
 
Math对象
- Math 对象的常用属性:
E :返回常数 e (2.718281828…)。
LN2 :返回 2 的自然对数 (ln 2)。
LN10 :返回 10 的自然对数 (ln 10)。
LOG2E :返回以 2 为底的 e 的对数 (log2e)。
LOG10E :返回以 10 为底的 e 的对数 (log10e)。
PI :返回 π(3.1415926535…)。
SQRT1_2 :返回 1/2 的平方根。
SQRT2 :返回 2 的平方根。 - Math 对象的常用方法:
abs(x) :返回 x 的绝对值。
round(x) :返回 x 四舍五入后的值。
sqrt(x) :返回 x 的平方根。
ceil(x) :返回大于等于 x 的最小整数。
floor(x) :返回小于等于 x 的最大整数。
sin(x) :返回 x 的正弦。
cos(x) :返回 x 的余弦。
tan(x) :返回 x 的正切。
acos(x) :返回 x 的反余弦值(余弦值等于 x 的角度),用弧度表示。
asin(x) :返回 x 的反正弦值。
atan(x) :返回 x 的反正切值。
exp(x) :返回 e 的 x 次幂 (e^x)。
pow(n, m) :返回 n 的 m 次幂 (nm)。
log(x) :返回 x 的自然对数 (ln x)。
max(a, b) :返回 a, b 中较大的数。
min(a, b) :返回 a, b 中较小的数。
random() :返回大于 0 小于 1 的一个随机数。 
创建对象
- 通过对象字面量来创建
 
var student={
	name:'zhangsan',
	age:18,
	gender:"male",
	sayHi:function(){
	console.log("hi,my name is"+this.name)
	},
}
 
- 通过new Object()创建对象
 
function Student(name, age, gender) {
  this.name = name;
  this.age = age;
  this.gender = gender;
  this.sayHi = function () {
    console.log("hi,my name is " + this.name);
  };
}
var s1 = new Student("zhangsan", 18, "male");
 
- 通过工厂函数创建对象
 
function createStudent(name, age, gender) {
  var student = new Object();
  student.name = name;
  student.age = age;
  student.gender = gender;
  student.sayHi = function () {
    console.log("hi,my name is " + this.name);
  };
  return student;
}
var s1 = createStudent("zhangsan", 18, "male");
 
- 自定义构造函数
 
function createStudent(name, age, gender) {
  var student = new Object();
  student.name = name;
  student.age = age;
  student.gender = gender;
  student.sayHi = function () {
    console.log("hi,my name is " + this.name);
  };
  return student;
}
var s1 = createStudent("zhangsan", 18, "male");










