0
result: [,…]

0: {id: "58cdb1a0", type: "b", nextDate: null, status: "active",…}
Date: "2019-11-27T11:10:23.000Z"
id: "58cdb1b86"
nextDate: null
status: "active"
type: "b"

1: {id: "e7b07030-799d-43", type: "l", nextDate: "2019-12-11T00:00:00.000Z",…}
Date: null
id: "e7b07030"
nextDate: "2019-12-11T00:00:00.000Z"
status: "active"
type: "l"

Then I want to access type ===b element object

const details = this.state.Method.filter((element: any) => element.type === 'b');

Then I want to get those object elements

console.log('details.nextDate');

But console getting undefined. Can you please help me to resolve it?

1
  • Need to see more code. Can't see anything wrong with your details constant or the filter. So I suspect it may have something to do with the way you are setting state. Commented Nov 24, 2019 at 4:29

2 Answers 2

1

Filter will return an array. So you can read the output as

console.log(details[0].nextDate);

OR

You can use find, which will return an object.

const details = this.state.Method.find((element: any) => element.type === 'b');

Now you can use

console.log(details.nextDate);
Sign up to request clarification or add additional context in comments.

Comments

1
console.log(details[0].nextDate);

The filter() method creates a new array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.