0

The following code produces always an error:

var index = this.dataSource.findIndex(item => item.id_system === row.id_system);

The error message is: TypeError: this.dataSource.findIndex is not a function

What could be the solution?

7
  • 2
    null.findIndex, undefined.findIndex, {...}.findIndex, you need to have an array on findIndex, check the value of dataSource by console logging it Commented Jul 17, 2020 at 9:25
  • Is dataSource an array? Commented Jul 17, 2020 at 9:26
  • The solution is to make sure that this.dataSource is something that has a findIndex() function. Probably an array is what you're expecting. Commented Jul 17, 2020 at 9:27
  • [ {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, ]; Commented Jul 17, 2020 at 9:28
  • this would be an example datasource Commented Jul 17, 2020 at 9:29

1 Answer 1

2

If you're using Angular Material example, then you will need to use data array.

Your dataSource should be MatTableDataSource<your type>.

So maybe you can try

let index = this.dataSource.data.findIndex(item => item.id_system === row.id_system);
Sign up to request clarification or add additional context in comments.

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.