Here is what I have:
fields = [ { apple: 'red' }, { banana: 'yellow' } ]
fields.forEach(field => {
// trying to get the key here
if (Object.keys(field)[0] === 'apple')
console.log('works!')
})
I want to ask is there a simple way for me to get the key? I feel I was making it too complicated by using
Object.key(field)[0]
add: I am just trying to get each key from this array of object and compare with a string.