var str1 = "Hello "; var str2 = "world!"; var n = str1.concat(str2); Hello world! 输出效果
注重: every() 不会对空数组举行检测。
注重: every() 不会改变原始数组。
例子:
var ages = [32, 33, 16, 40]; function checkAdult(age) { return age >= 18; } function myFunction() { document.getElementById("demo").innerHTML = ages.every(checkAdult); } false 输出效果
var ages = [32, 33, 16, 40]; function checkAdult(age) { return age >= 18; } function myFunction() { document.getElementById("demo").innerHTML = ages.filter(checkAdult); } 32,33,40 输出效果
<button onclick="numbers.forEach(myFunction)">点我</button> <p id="demo"></p> <script> demoP = document.getElementById("demo"); var numbers = [4, 9, 16, 25]; function myFunction(item, index) { demoP.innerHTML = demoP.innerHTML + "index[" + index + "]: " + item + "<br>"; } </script> 输出效果 index[0]: 4 index[1]: 9 index[2]: 16 index[3]: 25
var fruits = ["Banana", "Orange", "Apple", "Mango"]; var a = fruits.indexOf("Apple"); 效果 2
var fruits = ["Banana", "Orange", "Apple", "Mango"]; var energy = fruits.join(); 效果 Banana,Orange,Apple,Mango
var fruits = ["Banana", "Orange", "Apple", "Mango"]; var a = fruits.lastIndexOf("Apple"); 效果 2
var numbers = [4, 9, 16, 25]; function myFunction() { x = document.getElementById("demo") x.innerHTML = numbers.map(Math.sqrt); } 效果 2,3,4,5
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.pop(); 返回 Banana,Orange,Apple
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi") 效果输出 Banana,Orange,Apple,Mango,Kiwi
var numbers = [65, 44, 12, 4]; function getSum(total, num) { return total + num; } function myFunction(item) { document.getElementById("demo").innerHTML = numbers.reduce(getSum); } 输出效果 125
var numbers = [65, 44, 12, 4]; function getSum(total, num) { return total + num; } function myFunction(item) { document.getElementById("demo").innerHTML = numbers.reduceRight(getSum); } 输出效果 125
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.reverse(); 输出效果 Mango,Apple,Orange,Banana
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.shift() 效果 Orange,Apple,Mango
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; var citrus = fruits.slice(1,3); 效果输出 Orange,Lemon
var ages = [3, 10, 18, 20]; function checkAdult(age) { return age >= 18; } function myFunction() { document.getElementById("demo").innerHTML = ages.some(checkAdult); } 输出效果 true
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.sort(); 输出效果 Apple,Banana,Mango,Orange
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.splice(2,0,"Lemon","Kiwi"); 输出效果 Banana,Orange,Lemon,Kiwi,Apple,Mango
var d=new Date(); var n=d.toLocaleString(); 输出效果 2019/11/7 下昼4:59:41
var d=new Date(); var n=d.toString();
Thu Nov 07 2019 17:00:09 GMT+0800 (中国标准时间)
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.unshift("Lemon","Pineapple"); fruits 将输出: Lemon,Pineapple,Banana,Orange,Apple,Mango
1.阿里云: 本站现在使用的是阿里云主机,平安/可靠/稳固。点击领取2000米代金券、领会最新阿里云产物的种种优惠流动点击进入
2.腾讯云: 提供云服务器、云数据库、云存储、视频与CDN、域名等服务。腾讯云各种产物的最新流动,优惠券领取点击进入
3.广告同盟: 整理了现在主流的广告同盟平台,若是你有流量,可以作为参考选择适合你的平台点击进入
链接: http://www.fly63.com/article/detial/6306