@@ -58,6 +58,7 @@ The filter iterates over the object's keys and creates an array containing the v
58
58
property. By default, the filter also attaches a new property ` $key ` to the value containing
59
59
the original key that was used in the object we are iterating over to reference the property.
60
60
61
+
61
62
## Not adding the ` $key ` property
62
63
63
64
If you don't want the ` $key ` property to be attached to each of the property values, you simply
@@ -69,17 +70,24 @@ put an additional parameter on the `toArray` filter:
69
70
</div >
70
71
```
71
72
73
+ ## Using ` $key ` with non-objects
74
+
75
+ Non-objects such as strings and numbers cannot have a new ` $key ` property attached to them.
76
+ If the object properties you are iterating over are not objects then you must either disable
77
+ the ` $key ` property or the filter will replace the non-object with a new object of the form:
78
+ ` { $key: key, $value: value } ` .
79
+
80
+
72
81
## Caveats
73
82
74
83
There are always issues when trying to iterate over properties in JavaScript and the ` toArray `
75
84
filter has its own set of things to be aware of when using it:
76
85
77
86
* It only works with plain Objects - don't try to filter arrays and strings with it.
78
87
* If you don't disable it, the filter will modify each property value with a new ` $key ` property.
79
- * If the object you are iterating over contains values that are not objects then you must disable
80
- the ` $key ` property or it will error - non-objects cannot have properties attached to them.
81
88
* This filter is not compatible with IE8. (It uses ` Object.keys ` and ` Object.defineProperty ` which
82
- don't work well or at all in Internet Explorer 8 (IE8).
89
+ don't work well or at all in Internet Explorer 8 (IE8).
90
+
83
91
84
92
## Example
85
93
0 commit comments