个人习惯用思维导图做笔记,重新敲一遍加深印象
js内置对象
Object Array Function Math Date String Number Boolean RegExp(正则表达式)
对象API
String属性
String方法
| | |
---|
str.charAt() | 获取字符串某一个下标字符 | |
str.concat() | 拼接字符串 | |
str.indexOf() | 判断字符串是否包含某个字符串。(返回第一次出现的位置) | |
str.lastIndexOf() | 获取某字符最后一次出现的位置 | |
str.substr() | 截取字符串 | |
str.replace(‘a’,‘b’) | 修改字符串 | 默认替换第一个匹配的字符,请使用正则表达式全局匹配 |
str.search() | 返回第一次和正则表达式匹配的索引,无结果时返回-1 | |
str.march() | 提取字符串中与正则表达式匹配的文本,返回数组 | |
str.toLowerCase() | 转小写 | |
str.toUpperCase() | 转大写 | |
str.split() | 分隔字符串 | |
str.trim() | 去除字符串两端的空格 | |
Array属性
Array方法
| | |
---|
arr.concat() | 连接数组 | |
arr.join() | 将数组元素拼接成字符串 | |
arr.pop() | 删除数组最后一个元素 | |
arr.push() | 往数组后面添加一个元素 | |
arr.reverse() | 翻转数组 | |
arr.shift() | 删除数组第一个元素 | |
arr.slice() | 选取数组指定区间的元素 | |
arr.soft() | 根据函数条件对数组排序 | soft(function(){retrun a-b})//升序 |
arr.indexof() | 返回指定字符串第一次出现位置的下标 | |
arr.filter() | 根据一个函数条件返回新数组,不会改变原数组 | filter(function(a){return a<10}) |
Number方法
| |
---|
toString() | 转为字符串 |
toFixed() | 返回指定位数的小数 |
Math属性
Math方法
| |
---|
Math.abs() | 返回绝对值 |
Math.ceil() | 向上取整 |
Math.floor() | 向下取整 |
Math.max(n1,n2,…) | 返回最大值 |
Math.min(n1,n2,…) | 返回最小值 |
Math.pow(n,e) | 指数运算 |
Math.sqrt() | 返回参数值的平方根 |
Math.log() | 返回以e为底的自然对数值 |
Math.exp() | e的指数 |
Math.round() | 四舍五入 |
Math.random() | 返回0~1的随机数。[0,1) |
console方法
| |
---|
console.log(text,text2,…) | 在console窗口输出信息 |
console.info() | console窗口输出信息,内容一般是正式的 |
console.debug() | 在console窗口输出信息 |
console.warn() | 输出信息,表示警告 |
console.error() | 输出信息,表示出错 |
console.table() | 将复合类型的数据转为表格显示 |
console.count() | 计数,输出被调用次数。 |
console.dir() | 可打印object对象 |
console.dirxml() | 显示DOM节点 |
console.time() | 计时开始 |
console.timeEnd() | 计时结束 |
console.profile() | 新建一个性能测试器 |
console.profileEnd() | 结束正在运行的性能测试器 |
console.clear() | 清除控制台的所有输出 |
Object方法
| |
---|
Obj.getOwnPropertyName() | 遍历对象不可枚举的属性 |
Function属性
| |
---|
caller | 获取调用当前函数的引用(谁调用的函数) |
length | 获取函数形参个数 |
name | 获取函数名 |
arguments | 获取所有实参(arguments属性区分arguments关键字) |
Function方法
| |
---|
apply() | 修改this指向 |
call() | 修改this指向 |
valueOf() | 返回函数对象自身 |
toString() | 返回定义该Function对象的字符串 |
bind() | 修改this指向 |
数据类型转换
parseInt();转整型,从左往右解析,遇到非数字结束
parseFloat();转浮点型,从左往右解析,识别第一个小数点
Number(变量);将变量转数字
toString();将对象转字符
String(变量);将变量转字符,变量为undefined、null时不会报错
Boolean(变量);将变量转布尔值
!!();将变量转布尔值
Document对象属性
| |
---|
document.body | |
document.documentURI | 当前文档的网址 |
document.domain | 返回文档域名 |
document.lastModified | 返回文档最后修改时间戳 |
document.location | 返回location对象,提供文档URL信息 |
document.referrer | 返回文档访问来源 |
document.title | 返回文档标题 |
document.characterSet | 返回渲染当前文档的字符集 |
document.readyState | 返回当前文档的状态 |
document.designMode | 控制当前文档是否可编辑,可读写 |
document.compatMode | 返回浏览器处理文档的模式 |
document.cookie | 用来操作Cookie |
document.links | 返回当前文档的所有a元素 |
document.forms | 返回页面中所有表单元素 |
document.images | 返回页面中所有图片元素 |
document.embeds | 返回网页中所有嵌入对象 |
document.scripts | 返回当前文档的所有脚本 |
document.styleSheets | 返回当前网页的所有样式表 |
document.doctype | 返回与文档相关的文档类型声明 |
document.documentElement | 返回当前文档的根节点 |
document.defaultView | 返回document对象所在的window对象 |
document.head | 返回head元素 |
document.activeElement | 返回当前文档中获得焦点的那个元素 |
不定期更新…