【问题标题】:I just need to filter that an array of object from the array of objects我只需要从对象数组中过滤出一个对象数组
【发布时间】:2023-01-25 16:20:46
【问题描述】:
const array = [{id:1,name:"Lokesh"},{id:2,name:"veera"},{id:3,name:"lucky"}];
const array1 = [{id:1,name:"Lokesh"},{id:4,name:"mukesh",{id:5,name:"techno"}}];

过滤器后所需的输出是:- 包含这些对象的数组。

const array3 = [{id:4,name:"mukesh",{id:5,name:"techno"}];

【问题讨论】:

  • 即使它能够从给出的例子中推断出来,你应该正确地解释这背后的逻辑。并解释你尝试了什么,resp。这到底是怎么给你带来麻烦的。

标签: javascript php reactjs angular vue.js


【解决方案1】:

你可以使用 array.filter (ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

是这样的:

const array3 = array1.filter(el => el.name === "mukesh" || el.name === "techno")

【讨论】:

    猜你喜欢
    • 2023-02-03
    • 2019-05-05
    • 1970-01-01
    • 2018-10-03
    • 2021-05-14
    • 2020-08-15
    • 2019-07-18
    相关资源
    最近更新 更多