use*_*108 1 javascript indexing jquery object-property
a = {b:'bb',c:'cc',d:'dd'};
$.each(a, function(index){
// here 'index' is a string variable containing the property name, ie 'b', 'c' or 'd'.
}
Run Code Online (Sandbox Code Playgroud)
我想要属性的整数索引 - 这可能不使用独立的计数变量吗?
你可以这样做:
Object.keys( a ).forEach(function ( name, index ) {
var value = a[name];
name // the property name
value // the value of that property
index // the counter
});
Run Code Online (Sandbox Code Playgroud)
这是ES5 API,因此IE8需要es5-shim.