Re: [OT] javascript guru out there?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mike,

> I've been developing a javascript application that works everywhere
> except on Google's Chrome browser and have tracked it down to a "for
> each" statement.

You don't need the 'each' keyword in the 'for' statement. And if
you're looking to iterate through an array, you're much better off
doing something like:

var x = [1, 2, 3];
var len = x.length;
var i;
for (i = 0; i < len; i++) {
  // do whatever you need to with x[i] here
}

or using a shorter-handed version like:

var x = [1, 2, 3];
for (var i = 0; i < x.length; i++) {
  // ...
}

...if you can't be bothered to declare the variables separately
(though for large arrays, note that the second version is slower).

And if you really need to iterate through a collection contained in an
object, you can do something like:

var foo = {
  key1: 'val1',
  key2: 'val2',
  // ...
};

// this iterates all properties of 'foo', including possibly inherited
properties
for (var i in foo) {

  // we only want local properties of 'foo', so check this before
continuing as expected
  if (foo.hasOwnProperty(i)) {
    // ...
  }

}


> If anybody wants to take a peek/stab at this I could sure use the help -
> I've been stumped on this for two days now.
>
>         http://www.pastebin.com/Pq5E8Tfe

...all of the above being said, you might find faster (and more
detailed help) on a site generally geared more towards these types of
problems (general programming problems) on a site like
stackoverflow.com.


--Mike
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux