8000 edit array extension methods · mitar/vuejs.org@f849812 · GitHub
[go: up one dir, main page]

Skip to content

Commit f849812

Browse files
committed
edit array extension methods
1 parent 746d565 commit f849812

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/api/index.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,34 +2186,36 @@ type: api
21862186

21872187
## Array Extension Methods
21882188

2189+
Vue.js extends `Array.prototype` with two additional methods that makes it easier to perform some common Array operations while ensuring reactive updates are properly triggered.
2190+
21892191
### array.$set(index, value)
21902192

21912193
- **Arguments**
21922194
- `{Number} index`
21932195
- `{*} value`
21942196

21952197
- **Usage**
2196-
2198+
21972199
Set an element in the array to a value by index and trigger view updates.
21982200

21992201
``` js
2200-
vm.animals.$set(0, { name: 'Aardvark' })
2202+
vm.animals.$set(0, { name: 'Aardvark' })
22012203
```
22022204

2203-
- **See also:** [Mutation Methods](/guide/list.html#Mutation-Methods)
2205+
- **See also:** [Array Detection Caveats](/guide/list.html#Caveats)
22042206

22052207
### array.$remove(reference)
22062208

22072209
- **Arguments**
22082210
- `{Reference} reference`
22092211

22102212
- **Usage**
2211-
2212-
Remove an element from an array by reference and trigger view updates.
2213+
2214+
Remove an element from an array by reference and trigger view updates. This is a sugar method for first searching for the element in the array, and then if found, calling `array.splice(index, 1)`.
22132215

22142216
``` js
2215-
var aardvark = vm.animals[0]
2216-
vm.animals.$remove(aardvark)
2217+
var aardvark = vm.animals[0]
2218+
vm.animals.$remove(aardvark)
22172219
```
22182220

2219-
- **See also:** [Mutation Methods](/guide/list.html#Mutation-Methods)
2221+
- **See also:** [Mutation Methods](/guide/list.html#Mutation-Methods)

0 commit comments

Comments
 (0)
0