how do I iterate over object literal array with jquery $.each() method?
In the chrome debugger, it comes back as “undefined, undefined”.
Any help would be really appreciated. thanks!
var links = [
{ className : 'hover', url : 'http://www.yahoo.com' },
{ className : 'hover-2', url : 'http://www.foxnews.com' },
];
loopy(links)
function loopy(obj){
$.each(
obj,
function(){
console.log(obj.className + ', ' + obj.url);
}
);
}
Try:
The
$.eachfunction parameter takes two arguments — the index of the current item in the array, and the second is the actual current value of the array.See the API for some more explanation and examples.
You can see this fiddle to see it in action.