es6下的高階函式

2021-10-23 19:38:23 字數 1181 閱讀 1115

flter函式 返回乙個新的陣列 每次會根據條件進行一次判斷 支返回為true的一項 。

map函式 對陣列的每一項進行操作 返回每一項的陣列。

陣列物件可以直接取出自己想要的物件

let arr =[,

,];let res = arr.

map(()

=>()

) console.

log(res)

reduce 第一引數是上次返回的值 第二個引數是這一次使用的值。

split 篩選陣列 arr.splilt(』-』,3);引數二是返回陣列的前三項。

去掉空陣列空字串、undefined、null

var newarr = arr.

filter

(item => item)

陣列去重

var arr =[1

,2,2

,3,4

,5,5

,6,7

,7,8

,8,0

,8,6

,3,4

,56,2

];var arr2 = arr.

filter

((x, index,self)

=>self.

indexof

(x)===index)

console.

log(arr2)

;//[1, 2, 3, 4, 5, 6, 7, 8, 0, 56]

//此處的self其實就是arr原陣列

物件object.keys(arr);可以獲取物件的key

object.values(arr);可以獲取物件的value值

indexof返回某個指定的字串值在字串中首次出現的位置。

const arr =[1

,2,3

,4,5

,6,7

]const list =[,

,,,]

const params = list.

filter

(item=> arr.

indexof

(item.openid)

>-1

)console.

log(params)

es6箭頭函式

本例是在了解es6知識後在原來定義函式的基礎上進行理解var searchvalue 查詢匹配物件 var button var input var select button if searchvalue.input undefined button.click else 重新整理 tableli...

ES6 函式擴充套件

函式在js裡是相當重要的一部分了,es6裡也新增了一些函式方法,來看一下 test hello hello world test hello kill hello kill es6增加了函式引數預設值,可以直接在宣告引數的同時賦預設值,但是也可以後面重新賦值 test2 kill 括號內有引數x時,...

es6 箭頭函式

1.單引數 function cheng a 3 let cheng a 3 a a console.log cheng 9 2.多引數 function add a,b let add a,b a b 預設返回值 console.log add 3,9 3.無返回值 function add a,...