How to view javascript array without using indexes in YUI?

I know that jQuery and prototype have a $ .each () function to iterate over each element of the array. Does YUI help?

+5
source share
3 answers

YAHOO.util.Dom has a batch function that has the following signature:

Any | Array package (el, method, o, override)

If el is a DOM element or an array of DOM elements, a method is a function that will pass each element in the array as the first argument, o is an optional second argument, and an override is a boolean that determines if the area should be a window (false) or o (true)

, :

function setDisplay(el, display) {
    el.style.display = display;
}

YAHOO.util.Dom.batch(document.getElementsByTagName('div'), setDisplay, 'none');

, .

+7

?

for(var i=0; i<ary.length; i++)
  // assuming that ary[] contains objects with a DoSometing() method
  ary[i].doSomething();  
+5

YUI3:

Y.Array.each(myArray, function(element) {
    Y.log(element);
});

:

Y.Array.each(myArray, function(element, index, array) {
    ...
});
+2

All Articles