JavaScript Cheat Sheet

Clear an array

array.length = 0

linq.js example

Enumerable
   .from(some_array)
   .where(i => i.prop == test_value)
   .select(i => {"a":i.a_val, "b":i.b_val})
   .distinct(s => s["a"])
   .toArray();

jQuery create new element, attach an event, and add it to the list of elements of a parent element

jQuery("<span id='test'>Some text</span>")
   .on("click", function() { alert(this.id + ' clicked') })
   .append("#container");

jQuery clear contents of an element

jQuery("#target").empty();

URL encode/decode string

encodeURIComponent(string); //to URL econded
unescape(string); //from URL encoded

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s