JavaScript Object.keys returns an empty array

I am trying to get the keys to a JavaScript object. When I check the object, I see that there are a couple of key values ​​on the object, but when I start Object.keys(myObject), I get an empty array. What am I doing wrong?

enter image description here

I follow this documentation here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

And the function that creates the object is as follows:

query: function () {
  var query = {}
  _.each(this.$el.find('input:checked'), function (el, index) {
    Object.defineProperty(query, el.id, {value: el.value})
  })
  return query
}
+4
source share
2 answers

Object.keysreturns only enumerated private keys. Give it a try Object.getOwnPropertyNames.

+4
source

Console.log , .

, , .

 console.log(JSON.parse(JSON.stringify(keys)));
0

Source: https://habr.com/ru/post/1614645/


All Articles