JavaScript Object.keys returning empty array

Linda Keating

I'm trying to get the keys from a JavaScript Object. When I inspect the object I can see that there is a key value pair on the object but when I run Object.keys(myObject) I get an empty array returned. What am I doing wrong?

enter image description here

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

And the function which 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
}
Benjamin Gruenbaum

Object.keys only returns enumerable own keys. Try Object.getOwnPropertyNames.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Javascript(React) Object.keys and Object.getOwnPropertyNames are returning empty array

Javascript filter returning empty array

Promise JavaScript Returning Empty Array

Javascript function returning array empty

Javascript for loop returning empty array

Array filtering in JavaScript is returning an empty array

Javascript: Object have keys, but Object.keys returns empty

Removing empty object keys in an array of objects

Object.keys returns Empty Array

javascript get object keys in array

Javascript map question returning an array with empty values

Javascript returning "empty" strings inside an array

Create an empty two dimensional array in Javascript, with keys

Javascript - Recursively looking for keys in array with empty values

Javascript: if an array has object or is no empty

Javascript reduce array of object into one object with keys

Why passing function object to Object.keys() returns empty array?

Object typing where value is array of keys or empty array

why Object.keys(Array.prototype) returns empty array?

while sorting js object of arrays, it is returning keys array instead of objects

Returning an object which has keys as the values of passed array

Javascript array object return empty array

Returning key values from an array of object Javascript

activatedRoute returning empty object

Query returning an empty object

Rails find_by_sql returning array with empty object

Json_decode returning empty value - json object to php array

Create an array based on the keys of a JavaScript object

Converting JavaScript object with numeric keys into array