需要帮助访问复杂数组对象中的ID属性

时间:2019-04-11 03:04:35

标签: javascript arrays reactjs filtering

尝试通过我从this.match.params对象获取的ID过滤此数组时遇到问题。我正在尝试将其与数组中的ID相匹配,以进行检查,但我一直未定义。

我尝试使用ID过滤,但这由于可能未过滤正确的对象而返回空匹配

常量ID = this.props.match.params === cju980jb901l00740i07skgpc 所以这个id是我要过滤的那个id,但是我似乎无法使用array.filter((review => review.id === id)

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: {…}, …}

1 个答案:

答案 0 :(得分:0)

这将通过import sys while True: try: horas = int(input("¿Cuántas horas trabajó por semana? ")) except TypeError as exception: print("Solo números enteros") return horas 将其过滤掉:

id