一、reverse()函数:功能将数组倒序
例如:var myArray= New Array(3);
myArray[0]="Apple";
myArray[1]="Bananer";
myArray[2]="Orange";
document.write(myArray);
doucment.write(myArray.reverse());
输出: Apple Bananer Orange
Orange Bananer Apple
二、split() 函数:功能将字符串分割成字符串数组
格式:string.split(separator,howmany)
例如:"I am a student".split(' ');输出:["I","am","a","student"];
1.假如要获取分割后成的字符串数组的一部分:即使用“howmany”参数:
例如:"I am a student".split(' ',2);输出:["I","am"];
2.单个字符串分割成数组:"Apple".split(' ') 输出:['A','p','p','l','e'];
三、join()函数:功能将数组元素按指定的字符串联成字符串。
格式:Array.join(' ');
例如:var myArray=New Array(4);
myArray[0]="I";
myArray[1]="am";
myArray[2]="a";
myArray[3]="student";
document.write(myArray.join(' '));
输出:"I am a student"
四、slice(star,end)函数:功能在已有的数组元素中选取指定位置的元素组成新的数组
例如:var myArray=New Array(3);
myArray[0]="car";
myArray[1]="bus";
myArray[2]="bike"
myArray[3]="plane"
document.write(myArray.slice(1))
输出:["bus","bike","plane"]
document.write(myArray.slice(1,2))
输出:["bus","bike","plane"]
五、stringObject.charAt(index)函数:返回指定位置的字符
例如:document.write("Student".charAt(2) ) 输出:u
六、stringObject.toUpperCase()函数:字母转大写
七、Array.filter()方法
定义和用法
filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。
注意: filter() 不会对空数组进行检测。
注意: filter() 不会改变原始数组。
array.filter(function(currentValue,index,arr), thisValue)
例如:
<p>最小年龄: <input type="number" id="ageToCheck" value="18"></p>
<button onclick="myFunction()">点我</button>
<p>所有大于指定数组的元素有? <span id="demo"></span></p>
<script>
var ages = [32, 33, 12, 40];
function checkAdult(age) {
return age >= document.getElementById("ageToCheck").value;
}
function myFunction() {
document.getElementById("demo").innerHTML = ages.filter(checkAdult);
}
</script>