search
HomeWeb Front-endJS TutorialSummary of common Js methods
Summary of common Js methodsSep 19, 2017 am 09:31 AM
javascriptSummarizemethod

1. String

chatAt()   //返回在指定位置的字符,第一个位置是0。(string.chatAt(0))
concat()   //连接两个或更多字符串,返回新的字符串(string.concat(string1, string2, ..., stringX))
indexOf()   //返回某个指定的字符串值在字符串中首次出现的位置。区分大小写,如果没有找到匹配的字符串则返回 -1。(string.indexOf("aa"))
lastIndexOf()  //查找字符串值在字符串中最后出现的位置。从后向前搜索。
match()   //查找一个或多个正则表达式的匹配,(string.match(regexp))replace()  //查找到匹配的子串,并替换与正则表达式匹配的子串。(string.replace(searchvalue,newvalue))
search()   //查找与正则表达式匹配的值。如果没有匹配到,则返回-1.(string.search(searchvalue))
slice()   //提取字符串的片断,并在新的字符串中返回被提取的部分。(string.slice(start,end))
substr()   //从起始索引号提取字符串中指定数目的字符。(string.substr(start,length))
split()   //把字符串分隔成字符串数组。(string.split(separator,limit))substring()   //用于提取字符串中介于两个指定下标之间的字符,包括开始处的字符,但不包括结束处的字符。(string.substring(from, to))
toLowerCase()  //把字符串转换为小写。(string.toLowerCase())
toUpperCase()  //把字符串转换为大写。(string.toUpperCase())
trim()  //去除字符串两边的空白。

2. Number

toFixed(x)  //把数字转换为字符串,结果的小数点后有指定位数的数字。(number.toFixed(x))
toString()  //把数字转换为字符串

3. Array

concat()  //连接两个或更多的数组,并返回结果。(array1.concat(array2,array3,...,arrayX))
every()   //检测数值元素的每个元素是否都符合条件。如果所有元素都通过检测返回 true,否则返回 false。(array.every(function(currentValue,index,arr), thisValue))(currentValue,当前值。
index:可选,当前索引;arr:可选,当前元素属于的数组对象;thisValue:可选,对象作为执行回调时使用,用作this的值。)
filter()   //检测数值元素,并返回符合条件所有元素的数组。创建一个新的数组,新数组中的元素都是通过检查指定数组中符合条件的所有元素。(array.filter(function(currentValue,index,arr), thisValue))
indexOf()   //返回某个指定的字符串值在字符串中首次出现的位置。(array.indexOf(item,start))(item:查找的元素;start:可选,开始检索的 )
join()  //把数组的所有元素放入一个字符串中。(array.join(separator))(separator:可选,分隔符,省略则用逗号连接。)
map()   //通过指定函数处理数组的每个元素,并返回处理后的数组。(array.map(function(currentValue,index,arr), thisValue))
pop()  //删除数组的最后一个元素并返回删除的元素。(array.pop())push()  //向数组的末尾添加一个或更多元素,并返回新的长度。(array.push(item1, item2, ..., itemX))
reverse()  //反转数组的元素顺序。(array.reverse())shift()   //删除并返回数组的第一个元素。(array.shift())
slice()   //选取数组的的一部分,并返回一个新数组。(array.slice(start, end))sort()   //对数组的元素进行排序。(array.sort(sortfunction))(  可选。规定排序顺序。必须是函数。)
splice()  //从数组中添加或删除元素。(array.splice(index,howmany,item1,.....,itemX))(index:添加或删除的位置;
howmany:必须,规定应该删除多少个元素,为0时表示不上;item1..表示要添加的元素)toString()  //把数组转换为字符串。
unshift()  /向数组的开头添加一个或更多元素,并返回新的长度。(array.unshift(item1,item2, ..., itemX))

4. Global

<code class="hljs javascript"></code><p><span class="hljs-built_in">decodeURI</span>()  <span class="hljs-comment">//解码某个编码的URI。(decodeURI(uri))</span></p><p><span class="hljs-comment">encodeURI()  //把字符串编码为URI。(encodeURI(uri))</span></p><p><span class="hljs-comment">eval()   //计算JavaScript字符串,并把它作为脚本代码来执行。(eval(string))</span></p><p><span class="hljs-comment">isNaN()  //检查其参数是否是非数字值。(isNaN(value))</span></p><p><span class="hljs-comment">parseFloat() //解析一个字符串并返回一个浮点数。  </span></p><p><span class="hljs-comment">parseInt() //解析一个字符串并返回一个整数。</span><br></p><p><span class="hljs-comment">Number()  //把对象的值转换为数字。(Number(object))</span><br></p><p><span class="hljs-comment">String()  //把对象的值转换为字符串。(String(object))</span><br></p>

The above is the detailed content of Summary of common Js methods. 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
es6数组怎么去掉重复并且重新排序es6数组怎么去掉重复并且重新排序May 05, 2022 pm 07:08 PM

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

JavaScript的Symbol类型、隐藏属性及全局注册表详解JavaScript的Symbol类型、隐藏属性及全局注册表详解Jun 02, 2022 am 11:50 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

原来利用纯CSS也能实现文字轮播与图片轮播!原来利用纯CSS也能实现文字轮播与图片轮播!Jun 10, 2022 pm 01:00 PM

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

JavaScript对象的构造函数和new操作符(实例详解)JavaScript对象的构造函数和new操作符(实例详解)May 10, 2022 pm 06:16 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

JavaScript面向对象详细解析之属性描述符JavaScript面向对象详细解析之属性描述符May 27, 2022 pm 05:29 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

javascript怎么移除元素点击事件javascript怎么移除元素点击事件Apr 11, 2022 pm 04:51 PM

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

整理总结JavaScript常见的BOM操作整理总结JavaScript常见的BOM操作Jun 01, 2022 am 11:43 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach是es6里的吗foreach是es6里的吗May 05, 2022 pm 05:59 PM

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment