Skip to content

Instantly share code, notes, and snippets.

@rhalp10
Last active September 17, 2020 11:57
Show Gist options
  • Save rhalp10/8a05d9beb1d4dac5794bd2aca1aa58a7 to your computer and use it in GitHub Desktop.
Save rhalp10/8a05d9beb1d4dac5794bd2aca1aa58a7 to your computer and use it in GitHub Desktop.
AJAX Object.length undefined in JavaScript
IF YOU ARE HAVING PROBLEM ON USING AJAX JSON AND THE DATA IS "UNDEFINED" AND CANNOT COUNT THE LENGHT.
I WOULD RECOMMEND TO USE THIS.
var jsonDataFromAjax = {};
var keys = Object.keys(jsonDataFromAjax);
for (var i = 0, len = keys.length; i < len; i++) {
console.log(jsonDataFromAjax[keys[i]]);
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment