web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

es6语法中最常见的9个函数介绍

620 ℃
           

下面web建站给大家介绍一下es6语法中最常见的9个函数介绍,它们分别是forEachfiltermapconcatfindfindIndexincludessplitsubstr等。

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

filter实现数组过滤,es6语法过滤方法合集

ES6语法中有哪些简单的字符串转数组方法

ES6如何实现模块化编程

ES6语法种有哪些判断方法

vue语法中methods箭头函数的基本用法吗?

标签: concat, es6语法, filter, find, findIndex, forEach, includes, map, split, substr

上面是“es6语法中最常见的9个函数介绍”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2423.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计1184个字,预计阅读时长8分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款免费可商用英文字体——Atkinson Hyperlegible
下一篇: 推荐一款免费好看的中文设计字体——字体传奇特战体
x 打工人ai神器