Hello, I'm new to JavaScript and ES6. Currently, I am working on a react-native app that utilizes Firebase and Redux. One of my action creators acts as a search bar function to fetch data from Firebase. Here's the code I have so far:
export const searchResult = () => {
const { currentUser } = firebase.auth();
return (dispatch) => {
firebase.database().ref(`/users/${currentUser.uid}/entries`)
.on('value', snapshot => {
const obj = snapshot.val();
The function above is functioning well. However, now I need to convert the retrieved data into an array instead of just objects.
const array1 = Object.keys(obj).map(function(key) {
return [obj[key]];
});
After successfully executing the previous code, I encountered an issue with the following section. My goal is to filter out elements in array1 based on what is entered in the search bar. For now, I have hard-coded 'element' for testing purposes until I figure out how to implement dynamic filtering.
const element = '0';
const array2 = array1.filter(array1.indexOf(element) !== -1);
dispatch({ type: SEARCH_RESULT_SUCCESS, payload: array2 });
});
};
};
Currently, it seems like this code is just returning false instead of actually filtering the objects that match the 'element'. Should I include another function to refine my logic? What do you think I might be missing here? Any assistance would be greatly appreciated! Thank you in advance!