2011 Dec 3, 6:46
Cool and (relatively) new methods on the JavaScript Array object are here in the most recent versions of your
favorite browser! More about them on ECMAScript5, MSDN, the IE blog, or Mozilla's documentation. Here's the list that's got me excited:
-
some & every
-
Does your callback function return true for any (some) or all (every) of the array's elements?
-
filter
-
Filters out elements for which your callback function returns false (in a new copy of the Array).
-
map
-
Each element is replaced with the result of it run through your callback function (in a new copy of the Array).
-
reduce & reduceRight
-
Your callback is called on each element in the array in sequence (from start to finish in reduce and from finish to start in reduceRight) with the result of the previous callback call passed to
the next. Reduce your array to a single value aggregated in any manner you like via your callback function.
-
forEach
-
Simply calls your callback passing in each element of your array in turn. I have vague performance concerns as compared to using a normal for loop.
-
indexOf & lastIndexOf
-
Finds the first or last (respectively) element in the array that matches the provided value via strict equality operator and returns the index of that element or -1 if there is no such element.
Surprisingly, no custom comparison callback method mechanism is provided.
-
javascript array technical programming 2011 Nov 17, 11:00
I had previously replaced my use of Delicious with Google Reader. Delicious had a number of issues during their switch over from Yahoo to the new owners and I was eventually fed up enough to
remove it from daily use. I used Delicious to do the following things:
- Create a list of things to read later
- Save things to read again in the future
- Search through things I read and enjoyed (esp via tags)
- Annotate and share things on my blog
I realized that since I did most of my web browsing in Google Reader now anyway I may as well make use of its features. I star things to note I want to read it later or save to read again
later. I can annotate with notes in Google Reader and I can share items to my web site by way of the shared items feed. Additionally for when I'm not in Google Reader there's a bookmarklet to add
an arbitrary web site as a shared item in Google Reader.
Of course I wrote this and switched over about 1 week before Google removed the sharing feature from Google Reader. I'm irritated but in practice it forced me to find a different option which has
worked out mostly better. New blog post coming soon about that...
blog delicious me technical google-reader google feed