js數組

變異方法 (mutation method)數組

push( { message: 'Baz' })    pop()    shift()    unshift( { message: 'Baz' })    splice(0,1, { message: 'Baz' }    sort()    reverse()

含義 向數組的末尾添加一個或更多元素,並返回新的長度 刪除並返回數組的最後一個元素 刪除並返回數組的第一個元素 向數組的開頭添加一個或更多元素,並返回新的長度 刪除元素,並向數組添加新元素 對數組的元素進行排序 顛倒數組中元素的順序
items前 "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]"
返回值 3 { message: 'Bar' } { message: 'Foo' } 3 [ { message: 'Foo' }] " [
{ message: 'Foo' },
{ message: 'Bar' }
]" " [
{ message: 'Bar' },
{ message: 'Foo' }
]"
items後 "items: [
{ message: 'Foo' },
{ message: 'Bar' },
{ message: 'Baz' }
]" "items: [
{ message: 'Foo' },
]" "items: [
{ message: 'Bar' }
]" "items: [
{ message: 'Baz' },
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Baz' }
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Bar' },
{ message: 'Foo' }
]"spa

clipboard.png

非變異方法(non-mutating method)code

filter()    concat()    slice(1)

含義 鏈接兩個或更多的數組,並返回結果
items前 "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]"
返回值 " [
{ message: 'Foo' },
{ message: 'Bar' },
{ message: 'Baz' }
]" [ { message: 'Bar' }]
items後 "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]" "items: [
{ message: 'Foo' },
{ message: 'Bar' }
]"排序

clipboard.png

相關文章
相關標籤/搜索