I'm trying to retrieve the value of "id" from a one-object-long array in React. (The data is coming from Firebase). I have tried every possible combination of code, but it always gives me back undefined (in Firefox).
So I have this array called "Original Data", and this is where I want to retrieve the "id" and store it in a variable. Then I tried to convert it into object by slicing to first element of arary (although I'm not sure if that's needed altogether). And then I'm trying to retrieve the id by calling the Object.id value, but it returns undefined.
I tried doing it with data.id (thinking maybe it's Firebase data structure), but it also doesn't work.
My code:
console.log("OriginalData")
console.log(OriginalData)
const ConvertingToObject = {... OriginalData.slice(0)}
const RetrievingID = ConvertingToObject.id
console.log("Converting to Object")
console.log(ConvertingToObject)
console.log("Retrieving ID")
console.log(RetrievingID)
Console log:
**OriginalData **
Array [ {…} ]
0: Object { data: {…}, id: "100" }
length: 1
<prototype>: Array []
**Converting to Object**
Object { 0: {…} }
0: Object { data: {…}, id: "100" }
<prototype>: Object { … }
**Retrieving ID **
undefined