Q:

React Native Filter data

I'm making a chat app with N participants, and want to search according to first name.
 const filteredData = this.state.rawData.filter(id => 
   id.members[0].first_name.toUpperCase().indexOf(event.toUpperCase())  !== -1
   ||
   id.members[1].first_name.toUpperCase().indexOf(event.toUpperCase())  !== -1
 ) 

is not acceptable, as there are n members, not always two.
const filteredData = this.state.rawData.filter(id => 
  id.members.forEach(element => {
    element.first_name.toUpperCase().indexOf(event.toUpperCase())  !== -1
  }
) 

Returns me that undefined is not an object 'element.first_name.toUpperCase'
Why?
EDIT:
Sample data
rawData: [
        {
          new: 0,
          id: '1',
          members:
            [
              {
                email: 'grantmarshall@test.com',
                first_name: 'Grant',
                last_name: 'Marshall',
                id: "1",
                last_login_time: 10002,
                phone_number: '1234665',
                phone_number_international: '+1',
                picture: '',
                status:'',
                username:'Grant Marshall',
                user:'',
              },
              {
                email: 'you@you.com',
                first_name: 'youfn',
                last_name: 'yousn',
                id: "5ad0007828b1930043a5303d",
                last_login_time: 10002,
                phone_number: '1234665',
                phone_number_international: '+1',
                picture: '',
                status:'',
                username:'youfn youfn',
                user:'',
              },

              { email: 'self@self.com' }],
          messages:
            [
              { chat_id: 1, _id: "1", from: 'Grant Marshall', text: 'roident est duis duis sit occaecat ea eiusmod laboris mollit', time: '9:22', parse_mode: 'none' }
              ,
              { chat_id: 1, _id: "5ad0007828b1930043a5303d", from: 'Dave Pilkinton', text: 'Should not display', time: '9:22', parse_mode: 'none' },

              { chat_id: 1, _id: "1", from: 'Grant Marshall', text: 'my second', time: '9:22', parse_mode: 'none' }
              ,
              { chat_id: 1, _id: "5ad0007828b1930043a5303d", from: 'Dave Pilkinton', text: 'my second Should not display', time: '9:22', parse_mode: 'none' },
            ]
        },

A:

It's because element.first_name is undefined in 3rd iteration of the array.
Change your condition to:
element.first_name && element.first_name.toUpperCase().indexOf(event.toUpperCase())  !== -1

