主题
unique
从数组或对象中移除重复取值。
语法
knap
{{ value | unique }}用法
- 数组中的对象按值比较。对于对象,重复的取值会被移除,并保留最后匹配的键。字符串原样返回。
示例
原始取值
json
{
"tags": [
"notes",
"ideas",
"notes"
]
}knap
{{ tags | unique }}md
["notes","ideas"]数组中的对象
json
{
"items": [
{
"a": 1
},
{
"b": 2
},
{
"a": 1
}
]
}knap
{{ items | unique }}md
[{"a":1},{"b":2}]重复的对象取值
json
{
"values": {
"first": "same",
"second": "different",
"third": "same"
}
}knap
{{ values | unique }}md
{"second":"different","third":"same"}