
下面web建站给大家介绍一下es6语法中最常见的9个函数介绍,它们分别是forEach、filter、map、concat、find、findIndex、includes、split、substr等。
forEach
let texts = "";
let arrs = ["Apple", "Orange", "Cherry", "Banana"];
arrs.forEach((item,index)=>{
texts += item + ',' ;
});
console.log(texts)
// Apple,Orange,Cherry,Banana,
filter
let numbers = [15, 2, 50, 55, 90, 5, 4, 9, 10]; console.log(numbers.filter(number => number % 2 == 1)); // [15, 55, 5, 9]
map
let arr = [1, 2, 3]; let newArr = arr.map(num => num * 2); console.log(newArr) // [2, 4, 6]
concat
let str1 = "你好,"; let str2 = "中国!"; let str3 = str1.concat(str2); console.log(str3) //你好,中国!
find
const fruits = [
{ name: "apple", count: 10 },
{ name: "banana", count: 18 },
{ name: "mango", count: 3 }
];
const findMango = fruits.find(fruit =>fruit.name === "mango");
console.log(findMango) //{name: 'mango', count: 3}
findIndex
const fruits = [
{ name: "apple", count: 10 },
{ name: "banana", count: 18 },
{ name: "mango", count: 3 }
];
const findMango = fruits.findIndex(fruit =>fruit.name === "mango");
console.log(findMango) //2
includes
const birds = ["Birds", "peacock", "Dove", "Sparrow"];
console.log(birds.includes("Dove")); //true
split
let text = "Hello wo name china";
console.log(text.split(" ", 3));
//['Hello', 'wo', 'name']
substr
const test = "Hello wo name china, who are you."; console.log(test.substr(0, 30)); //Hello wo name china, who are y
标签: concat, es6语法, filter, find, findIndex, forEach, includes, map, split, substr
上面是“es6语法中最常见的9个函数介绍”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2423.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

mysql语法报“Invalid default value for 'createTime“错误怎么解决
Qwen3-TTS:阿里通义Qwen开源的系列语音生成模型
AdsTurbo官网使用入口,Sora 2提供技术支持的AI视频广告生成工具
Cheetu AI官网使用入口,会议/访谈/音频内容处理的专业AI工具
DeepSearcher:结合 LLM 与向量数据库,隐私数据也能高精度分析
WindClaw官网使用入口,整合Wind专业金融数据库,支持用户创建多只AI智能体