Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Quick Reference - JavaScript

RSS
Modified on Fri, Nov 11, 2011, 1:13 PM by Administrator Categorized as (Favorites), JavaScript, jQuery, and Angular, Quick Reference

Number Object

MethodDescription
num.toFixed(x)Rounds off the number to x places after the decimal point

String Object

Functions

Adapted from here.

MethodDescription
s.charAt()Returns the character at the specified index
s.charCodeAt()Returns the Unicode of the character at the specified index
s.concat()Joins two or more string, returning a copy of the joined strings
s.fromCharCode()Converts Unicode values to characters
s.indexOf()Returns the position of the first occurrence of a specified value in a string
s.lastIndexOf()Returns the position of the last occurrence of a specified value in a string
s.match()Searches for a match between a regex and a string, returning the matches
s.replace()Searches for a match between a substring/regext and a string, replacing the matched substring with a new substring
s.search()Searches for a match between a regex and a string, returning the position of the match
s.slice()Extract a part of a string and returns a new string
s.split()Splits a string into an array of substrings()
s.substr()Extracts the characters from a string from a start position and length
s.substring()Extracts the characters from a string between two specified indices
s.toLowerCase()Converts a string to lowercase
s.toUpperCase()Converts a string to uppercase
s.valueOf()Returns the primitive value

Extensions

String.prototype.startsWith = function(prefix, caseSensitive) {

	if (caseSensitive == undefined) caseSensitive = true;
	
	if (caseSensitive)
		return (this.substr(0, prefix.length) == prefix);		
	else
		return(this.substr(0, prefix.length).toUpperCase() == prefix.toUpperCase());
    
}
String.prototype.contains = function(searchFor, caseSensitive){

    if (caseSensitive == undefined)
        caseSensitive = true;
        
    if (caseSensitive)
        return (this.indexOf(searchFor) >= 0);
    else    
        return (this.toUpperCase().indexOf(searchFor.toUpperCase()) >= 0);
        
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.