我如何在VUE3中过滤一个数组
我是Vue3的新手。
我必须过滤一个带有相同项目的数组,然后将结果推入另一个数组,
我的数组是
let list = [
{"name":"1000","properties":{"item":"1","unit":"DZN"}},
{"name":"2000","properties":{"item":"1","unit":"CTN"}},
{"name":"3000","properties":{"item":"2","unit":"DZN"}},
{"name":"4000","properties":{"item":"3","unit":"CTN"}}
]
我需要在另一个数组中使用条件item = 1
的相应名称。
结果数组将类似于[{“ name”:“ 1000”,“单元”:“ dzn”},{“ name”:“ 2000”,“ unit”:“ ctn”}]
>
tia
I am new to Vue3.
I have to filter a array with same item and push results into another array
My array is
let list = [
{"name":"1000","properties":{"item":"1","unit":"DZN"}},
{"name":"2000","properties":{"item":"1","unit":"CTN"}},
{"name":"3000","properties":{"item":"2","unit":"DZN"}},
{"name":"4000","properties":{"item":"3","unit":"CTN"}}
]
I need corresponding name with condition item =1
in another array.
Result array will be similar to [{"name":"1000", "unit":"DZN"}, {"name":"2000", "unit":"CTN"}]
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解,您想从具有 item item 值等于1的记录中创建具有 name 和 unit 属性的对象数组您必须首先过滤一个数组才能获取所需值的记录 item ,然后映射这些值以创建新的对象数组。
这是一个示例:
如果这是一个Vue3反应变量,请记住在filter()方法之前添加 .value
If I understand correctly you want to create an array of objects with name and unit attributes from records which have item values equal to 1. To do that you have to first filter an array to get only records which have desired value of item and then map those values to create a new array of objects.
Here is an example:
If this is a Vue3 reactive variable remember to add .value before filter() method to make it work