score:1
yes this is definitely achievable!
try: child.val()[variable]
in javascript, we can access an object's properties by either using dots or brackets. for example, object.property
or object["property"]
.
again, in your case, to access the firebase element with a variable, you could do child.val()[variable]
where variable is some string or integer to access the firebase object's property. perhaps variable = 5 or variable = '5'.
score:0
unfortunately you're going to be struggling with how the firebase client handles arrays here.
the firebase client will interpret your data as an array and convert it to:
"mywords" : {
"words" : [
null,
"tool box",
"ice cream",
"lavender",
"speakers",
"pepsi",
"windows",
"linux",
]
}
so it inserts an empty value in the first position of the array. if that is not a problem for your app, then you can accept this.
but for many apps this extra item is a problem. in those cases, we recommend that you prefix your numbers with some fixed string to ensure firebase doesn't does its string interpretation:
"mywords" : {
"words" : {
"item1" : "tool box",
"item2" : "ice cream",
"item3" : "lavender",
"item4" : "speakers",
"item5" : "pepsi",
"item6" : "windows",
"item7" : "linux",
}
}
see this blog post for more information about how firebase handles arrays: https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html
score:1
you just need to replace child.val().today ---> child.val()[my variable]
var my_variable = moment().isoweekday(); //friday is 5
var items = [];
snap.foreach((child) => {
items.push({
title: child.val().title,
profile:child.val().profile,
test:child.val().test,
special:child.val()[my_variable],
_key: child.key,
});
});
Source: stackoverflow.com
Related Query
- Firebase retrieve data dynamically
- How to retrieve data from firebase in React?
- How to retrieve data from firebase v9 to display it on the frontend?
- How to Retrieve and Render Data from Firebase using ID/Key (with React)?
- How to retrieve a data from API or Firebase before rendering anything to the user in React?
- Retrieving (allpost) data from firebase and using uid want to retrieve user information also
- Retrieve Data data once time Firebase instead of onSnapshot
- How do I retrieve the child of the child of the child's data from my firebase Realtime database?
- fetch data from firebase collections inside a collections dynamically in react
- Retrieve data from Firebase with javascript
- React BootstrapTable how to dynamically create rows for firebase data
- How do i convert code to retrieve data from Firebase V8 to Firebase V9 in Next.js
- Not Being Able To Retrieve My Data From Firebase V9
- Firebase firestore WEB v.9 retrieve data ID-s from collection where that current user ID contains
- Unable to retrieve data from Multiple collection firebase
- How to store/ retrieve data properly in firebase database
- Retrieve data from a ReadableStream object?
- React with Firebase - submitting Formik form data
- Rendering React components from json data dynamically
- Change series data dynamically in react-highcharts without re-render of the chart
- Dynamically inject data in React Router Routes
- Bind event handler to document & have access to firebase api data via useEffect
- Updating Data in Firebase using React
- Retrieve file from firebase storage
- Generating groupings within a Material UI Select component dynamically from data
- How to retrieve a referenced field data inside inputComponent in Sanity.io?
- Adding dynamically generated checkboxes to react-table and capturing row data
- retrieve data from asyncStorage in react native
- How do I add a React form data to a Firebase real-time database?
- Redux Store does not update state with created data on firebase real-time database
More Query from same tag
- I am trying to use a tool tip but not sure how to make the trigger work
- React/Javascript: Pass Function with optional Parameter as Prop
- Render multiple components with a single ternary operator
- Formik show validation error message after seperating into components
- Action on window resize in React
- Hosting Django And React with parcel bundler on Heroku
- Images array only shows once
- How to take out props data from a component in react-js?
- How to get submit form button to be on the next line css?
- React handleChange error with two components
- Why does a list element not initially render but does after a state change in React?
- Edit an entry with Formik and Yup doesn't recognize the existing fields
- React - Uncaught ReferenceError: add is not defined
- Display correct components on change with selected value from dropdown?
- react 15.5.4 enzyme shallow and mount are not working
- Two logical operators for the disabling the button
- Why CSS loader of webpack not working?
- React setState() callback issue, cant access to output variable
- School project with this error: Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null
- Fetching Objects of object from API in React JS
- Remove (or at least hide) card on react-admin List
- Got error: `RangeError: invalid time value` while set XAxis date value use date-fns
- "POST http://localhost:5000 net err failed"
- Getting payload not working on product detail page (React, Redux)
- Render the component lazily, on the select of a value change - React
- Get the response from the dispatch - React Redux
- TypeError: Cannot read property 'offsetHeight' of null when using the Locomotive Scroll react module
- Removing white space between integers - JavaScript / ReactJS
- measure state update from within event handler function
- Trying to Map Over an Array within Array and display in table