Javascript 需要帮助访问复杂数组对象中的ID属性吗
尝试按从this.match.params对象获取的ID筛选此数组时出现问题。我正在尝试将它与数组中的ID进行匹配,以供审阅,但我一直没有定义 我尝试使用按ID筛选,但由于可能未筛选正确的对象,因此返回空匹配 常量id=this.props.match.params===cju980jb901l00740i07skgpc 因此,这个id就是我试图筛选的id,但我似乎无法使用array.filter((review=>review.id==id)访问它Javascript 需要帮助访问复杂数组对象中的ID属性吗,javascript,arrays,reactjs,filtering,Javascript,Arrays,Reactjs,Filtering,尝试按从this.match.params对象获取的ID筛选此数组时出现问题。我正在尝试将它与数组中的ID进行匹配,以供审阅,但我一直没有定义 我尝试使用按ID筛选,但由于可能未筛选正确的对象,因此返回空匹配 常量id=this.props.match.params===cju980jb901l00740i07skgpc 因此,这个id就是我试图筛选的id,但我似乎无法使用array.filter((review=>review.id==id)访问它 这将通过id将其过滤掉: const ar
这将通过
id
将其过滤掉:
const arr=[{
作者:{
id:“cju9808n401fo0740rbqgej9p”,
用户名:“asdfsd”,
电子邮件:“asldkf@gmail.com",
__typename:“用户”
},
已审查项目:{
id:“cju980j9a01kd07407qvtwh5o”,
名称:“艾米的第一个项目”,
标题:“http://lorempixel.com/400/400/”,
__类型名称:“项目”
},
id:“cju980jb901l00740i07skgpc”,
姓名:“干得好!”,
文字:“我真的很喜欢你这样做。”,
时间戳:“2019-04-05T00:00:00.000Z”
},
{
作者:{
id:“cju9808n401fo0740rbqgej9p”,
用户名:“asdfsd”,
电子邮件:“asldkf@gmail.com",
__typename:“用户”
},
已审查项目:{
id:“cju980j9a01kd07407qvtwh5o”,
名称:“艾米的第一个项目”,
标题:“http://lorempixel.com/400/400/”,
__类型名称:“项目”
},
id:“1cju980jb901l00740i07skgpc”,
姓名:“干得好!”,
文字:“我真的很喜欢你这样做。”,
时间戳:“2019-04-05T00:00:00.000Z”
}
];
常数matchId='cju980jb901l00740i07skgpc';
设res=arr.filter(({
身份证件
})=>id===matchId);
console.log(res);
请不要从控制台复制pase。提供简短而真实的数据(不是从控制台);这是关于React中的状态,我正在将此数组设置为状态,我们正在使用GraphQL。不确定您希望我发布什么,请详细说明您的任务,我的意思是您的数据不可读。请添加我们可以测试和轻松读取的数据。您可以对数据使用JSON.stringify()
,然后粘贴到此处。
0:
Author: {id: "cju9808n401fo0740rbqgej9p", username: "asdfsd",
email: "asldkf@gmail.com", __typename: "User"}
ProjectReviewed: {id: "cju980j9a01kd07407qvtwh5o", name: "Amy's 1st
Project", titleImg: "http://lorempixel.com/400/400/", __typename:
"Project"}
id: "cju980jb901l00740i07skgpc"
name: "Nice Job!"
text: "I really like how you did this."
timestamp: "2019-04-05T00:00:00.000Z"
__typename: "Review"
__proto__: Object
1: {id: "cju980jcz01l80740jwohw41e", name: "Wicked", text: "You're
a rockstar!", timestamp: "2019-04-01T00:00:00.000Z", Author: {…},
…}
2: {id: "cju980jdh01lg0740j8o4u60o", name: "Well Done", text: "I'm
amazed - truly.", timestamp: "2019-03-19T00:00:00.000Z", Author:
{…}, …}
3: {id: "cju980jdy01lo0740mmo1yfkf", name: "DiS iS TrASSh", text:
"Thank u, next!", timestamp: "2019-01-12T00:00:00.000Z", Author:
{…}, …}
4: {id: "cju980jev01lw0740p6k8r7d3", name: "Teach Me How to Do
This!", text: "Notice me senpai", timestamp: "2019-02-
19T00:00:00.000Z", Author: {…}, …}
5: {id: "cju980jfs01m40740pe5gxn9a", name: "This is nice", text:
"...real nice", timestamp: "2019-01-11T00:00:00.000Z", Author: {…},
…}
6: {id: "cju980jge01mc0740mqyu5zi3", name: "Noob", text: "Why are
you even posting a tutorial about something you know nothing
about?", timestamp: "2018-07-14T00:00:00.000Z", Author: {…}, …}
7: {id: "cju980jgx01mk0740g1ehxjsf", name: "Wow", text: "You gotta
create more of these.", timestamp: "2019-04-01T00:00:00.000Z",
Author: {…}, …}
8: {id: "cju980jb901l00740i07skgpc", name: "Nice Job!", text: "I
really like how you did this.", timestamp: "2019-04-
05T00:00:00.000Z", Author: {…}, …}
9: {id: "cju980jcz01l80740jwohw41e", name: "Wicked", text: "You're
a rockstar!", timestamp: "2019-04-01T00:00:00.000Z", Author: {…},
…}
10: {id: "cju980jdh01lg0740j8o4u60o", name: "Well Done", text: "I'm
amazed - truly.", timestamp: "2019-03-19T00:00:00.000Z", Author:
{…}, …}
11: {id: "cju980jdy01lo0740mmo1yfkf", name: "DiS iS TrASSh", text:
"Thank u, next!", timestamp: "2019-01-12T00:00:00.000Z", Author:
{…}, …}
12: {id: "cju980jev01lw0740p6k8r7d3", name: "Teach Me How to Do
This!", text: "Notice me senpai", timestamp: "2019-02-
19T00:00:00.000Z", Author: {…}, …}
13: {id: "cju980jfs01m40740pe5gxn9a", name: "This is nice", text:
"...real nice", timestamp: "2019-01-11T00:00:00.000Z", Author: {…},
…}
14: {id: "cju980jge01mc0740mqyu5zi3", name: "Noob", text: "Why are
you even posting a tutorial about something you know nothing
about?", timestamp: "2018-07-14T00:00:00.000Z", Author: {…}, …}
15: {id: "cju980jgx01mk0740g1ehxjsf", name: "Wow", text: "You gotta
create more of these.", timestamp: "2019-04-01T00:00:00.000Z",
Author: {…}, …}