React native Array.find is not a function
I am a junior in js development so this might be a stupid question, so apologies.
I am using firebase in my application to store my strings, I call it once when the application is loaded and stores it in memory for faster access.
Then I use strings.find to find a specific string in the array. All jobs show up when running on iOS, but when running on Android I get this weird error all the time.
TypeError: Undefined is not a function (evaluting 'this.strings.find...
Here's my data schema
{'strings': [{'name':'something', 'value':'something'} ... ]
And here is my code
getString(name) {
return this.strings.find(x => x.name == name).value
}
And this is where I define the object
init(onUpdated) {
Promise.all([stringsDb.once('value'), multiLang.once('value')])
.then(([stringsSnapshot, multiLangSnapshot]) => {
this.strings = stringsSnapshot.value
this.multiLang = multiLangSnapshot.value
onUpdated(true)
})
.catch((err) => {
console.log(err.stack)
onUpdated(false)
});
}
source to share
This is probably because it is this.strings
not an array. you need to debug it and see if it is really an array or not, i guess it returns an object if then you need to use a reducer or maybe Object.values
or something to convert to an array.
ps, you must use operator ===
when comparing strings
source to share