变异方法 (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’}
]”
非变异方法(non-mutating method)
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’}
]”