I have amended a firebase structure from an array
{
"posts" : [
{
"code" : "BAcyDyQwcXX",
"caption" : "Lunch #hamont",
"likes" : 56,
"id" : "1161022966406956503",
"display_src" : "https://test1.jpg"
},
{
"code" : "BAcJeJrQca9",
"caption" : "Snow! ⛄️🌨❄️ #lifewithsnickers",
"likes" : 59,
"id" : "1160844458347054781",
"display_src" : "https://test2.jpg"
},
]
}
to a 'flattened' object
{
"posts" : {
"1161022966406956503" : {
"code" : "BAcyDyQwcXX",
"caption" : "Lunch #hamont",
"likes" : 56,
"display_src" : "https://test1.jpg"
},
"1160844458347054781" : {
"code" : "BAcJeJrQca9",
"caption" : "Snow! ⛄️🌨❄️ #lifewithsnickers",
"likes" : 59,
"display_src" : "https://test2.jpg"
}
}
}
and now wish to refactor the following code to accommodate for the handling of an firebase object instead of an array:
const { postId } = this.props.params;
const i = this.props.posts.findIndex((post) => post.code === postId);
How do I do this?