|
-
Sep 25th, 2011, 11:29 AM
#3
Thread Starter
Stack Overflow moderator
Re: [JavaScript] Useful Methods
Place the line from #1 in your code, and use the functions:
- Array all:
Code:
[1, 2, 3, 4, 5].l(function(x) { return x <= 5; })
returns true because all of them are less than 5. - Array any:
Code:
[1, 2, 3, 4, 5].n(function(x) { return x >= 6; })
returns false because no element is more than or equal to 6. - Array where:
Code:
[1, 2, 3, 4, 5].w(function(x) { return x % 2 === 0; })
returns [2, 4]; the only numbers in the array that are odd. - String startsWith:
Code:
"Hello world".s("Hello")
returns true because "Hello world" starts with "Hello". - String endsWith is along the same lines as startsWith, and it's named "e".
- String indexOf is the default functionality with the shorter name of "i".
- String trim trims characters from both sides: returns "Fi" because 't's have been trimmed off both sides. If passed no argument, null or a blank string, it trims spaces.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|