for-loop iterate key - Iterating a JavaScript object's properties using jQuery

2 Answers

You can use each for objects too and not just for arrays:

var obj = {
    foo: "bar",
    baz: "quux"
jQuery.each(obj, function(name, value) {
    alert(name + ": " + value);
value each json

Is there a jQuery way to perform iteration over an object's members, such as in:

    for (var member in obj) {

I just don't like this for sticking out from amongst my lovely jQuery notation!

Late, but can be done by using Object.keys like,

var a={key1:'value1',key2:'value2',key3:'value3',key4:'value4'},
var keys = Object.keys(a);
   str+= '<li>'+keys[i]+' : '+a[keys[i]]+'</li>';
<ul id="object-keys"></ul>