Issue
In my project i push a array into a table in firebase realtime database. Firebase generate a token and not a numeric id for each array:
{
"-N2mToYDj-i8ToErmaUj": {
"anzahl": 2,
"groesse": 0.5,
"name": "getraenk1",
"preis": 5.5
},
"-N2mX3RPnDXxWMHMJScy": {
"anzahl": 1,
"groesse": "0.25",
"name": "getraenk2",
"preis": 2.2
},
"-N2mXBT8c7EKlIgyrU72": {
"anzahl": 1,
"groesse": "0.5",
"name": "getraenk3",
"preis": 3.4
},
"-N2mXZD1BoCslj81Lcya": {
"anzahl": 1,
"groesse": "1",
"name": "getraenk4",
"preis": 5.2
"-N2m_g8GutpAFqsN4WsP": {
"anzahl": 1,
"groesse": "0.33",
"name": "getraenk5",
"preis": 3.2
},
}
How can i work with each object when the key value is not numeric. ForEach() does not work for me.
Solution
Lets say your data stored in test
object.
you can use Object
function in javascript to work with any object. For accessing all key you can try this:
Object.keys(test).map(key => { // key in here can be for example -N2mToYDj-i8ToErmaUj
const data = test[key] // this is the full object that each key points to
/*
{
"anzahl": 2,
"groesse": 0.5,
"name": "getraenk1",
"preis": 5.5
}
*/
})
Answered By - Mohammadhossein hossein
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.