js 数组filter使用

let users = [
    {
        "name":'zhangshan',
        "age":14,
        "displayName":"张山"
    },
    {
        "name":'lisi',
        "age":15,
        "displayName":"李四"
    },
    {
        "name":'wangwu',
        "age":16,
        "displayName":"王五"
    },
    {
        "name":'sunliu',
        "age":17,
        "displayName":"孙刘"
    },
    {
        "name":'zhangshanhu',
        "age":20,
        "displayName":"张山虎"
    }
];

let orders = [
    {
        "creator":"zhangshan",
        "article":"phone"
    },
 {
        "creator":"zhangshan",
        "article":"pen"
    },
 {
        "creator":"wangwu",
        "article":"water"
    },
 {
        "creator":"sunliu",
        "article":"computer"
    },
 {
        "creator":"lisi",
        "article":"apple"
    },
 {
        "creator":"lisi",
        "article":"phone"
    },
 {
        "creator":"zhangshanhu",
        "article":"phone"
    }
];
//模糊查询张山的订单
let userArr = users.filter(u=>u.displayName.includes("张山"));
let result = orders.filter(o=>user.filter(u=>u.name === o.creator).length > 0);
//结果
result = [{
        "creator":"zhangshan",
        "article":"phone"
    },
     {
        "creator":"zhangshan",
        "article":"pen"
    },{
        "creator":"zhangshanhu",
        "article":"phone"
    }];

//模糊查询张山的订单
let userArr = users.filter(u=>u.displayName.includes("张山虎"));
let result = orders.filter(o=>user.filter(u=>u.name === o.creator).length > 0);

//结果
result = [{
        "creator":"zhangshanhu",
        "article":"phone"
    }];




相关推荐

  1. js 数组filter使用

    2024-05-16 12:56:04       5 阅读
  2. js filter,every,includes 过滤数组

    2024-05-16 12:56:04       20 阅读
  3. Vue.js(过滤器(Filter))

    2024-05-16 12:56:04       7 阅读
  4. 【Spring Boot 使用Filter统一处理请求数据转换】

    2024-05-16 12:56:04       21 阅读
  5. Filter过滤器学习使用

    2024-05-16 12:56:04       18 阅读
  6. django-filter使用

    2024-05-16 12:56:04       23 阅读

最近更新

  1. .Net Core WebAPI参数的传递方式

    2024-05-16 12:56:04       0 阅读
  2. QT--气泡框的实现

    2024-05-16 12:56:04       1 阅读
  3. LeetCode 968.监控二叉树 (hard)

    2024-05-16 12:56:04       0 阅读
  4. leetcode热题100.完全平方数(动态规划进阶)

    2024-05-16 12:56:04       0 阅读
  5. leetcode328-Odd Even Linked List

    2024-05-16 12:56:04       0 阅读
  6. C 语言设计模式(结构型)

    2024-05-16 12:56:04       0 阅读
  7. v-if 与 v-show(vue3条件渲染)

    2024-05-16 12:56:04       0 阅读
  8. kafka防止消息丢失配置

    2024-05-16 12:56:04       0 阅读

热门阅读

  1. RIP、OSPF、BGP等协议及华为路由器配置总结

    2024-05-16 12:56:04       4 阅读
  2. 40-2 了解与安装堡垒机

    2024-05-16 12:56:04       2 阅读
  3. Leetcode 404:左叶子之和

    2024-05-16 12:56:04       3 阅读
  4. 力扣:131. 分割回文串

    2024-05-16 12:56:04       3 阅读
  5. 力扣 72. 编辑距离 python AC

    2024-05-16 12:56:04       4 阅读
  6. 课时126:awk实践_进阶知识_内置函数1

    2024-05-16 12:56:04       4 阅读
  7. 【Python】学生管理系统

    2024-05-16 12:56:04       4 阅读