0

So i have this:

const somObj = {
    whatever : 1,
}

const somObj2 = {
    whatever : 2,
}

const arrayOfObj = [somObj, somObj2]

Is there any way to get the name of the objects as strings while looping for the array like this?

for (i in arrayOfObj){
    something(arrayOfObj[i])
}

being the return the string "somObj".

thank you

  • 1
    @CertainPerformance, looks like that duplicate flag points to getting values in the array. Whereas the OP is asking to return the variable name used to store it - the constant name 'somObj' – K Scandrett Jun 05 '22 at 01:32

0 Answers0