Skip to content

Instantly share code, notes, and snippets.

@unknownuser88
unknownuser88 / gist:8282794
Created January 6, 2014 13:20
return obj keys
//return obj keys
$.extend({
keys: function(obj){
var a = [];
$.each(obj, function(k){ a.push(k) });
return a;
},
eys: function(obj){
return 'test';
}
@unknownuser88
unknownuser88 / gist:8282806
Created January 6, 2014 13:21
charAt(x) Returns the character at the “x” position within the string.
//charAt(x)
var myString = 'jQuery FTW!!!';
console.log(myString.charAt(7));
//output: F
@unknownuser88
unknownuser88 / gist:8282822
Created January 6, 2014 13:23
concat(v1, v2,…) Combines one or more strings (arguments v1, v2 etc) into the existing one and returns the combined string. Original string is not modified
//concat(v1, v2,..)
var message="Sam"
var final=message.concat(" is a"," hopeless romantic.")
//alerts "Sam is a hopeless romantic."
alert(final)
@unknownuser88
unknownuser88 / gist:8282832
Created January 6, 2014 13:23
indexOf(substr, [start]) Searches and (if found) returns the index number of the searched character or substring within the string. If not found, -1 is returned. “Start” is an optional argument specifying the position within string to begin the search. Default is 0.
//indexOf(char/substring)
var sentence="Hi, my name is Sam!"
if (sentence.indexOf("Sam")!=-1)
alert("Sam is in there!")
@unknownuser88
unknownuser88 / gist:8282836
Created January 6, 2014 13:24
lastIndexOf(substr, [start]) Searches and (if found) returns the index number of the searched character or substring within the string. Searches the string from end to beginning. If not found, -1 is returned. “Start” is an optional argument specifying the position within string to begin the search. Default is string.length-1.
//lastIndexOf(substr, [start])
var myString = 'javascript rox';
console.log(myString.lastIndexOf('r'));
//output: 11
@unknownuser88
unknownuser88 / gist:8282843
Created January 6, 2014 13:24
match(regexp) Executes a search for a match within a string based on a regular expression. It returns an array of information or null if no match is found.
//match(regexp) //select integers only
var intRegex = /[0-9 -()+]+$/;
var myNumber = '999';
var myInt = myNumber.match(intRegex);
console.log(isInt);
//output: 999
@unknownuser88
unknownuser88 / gist:8282850
Created January 6, 2014 13:24
replace(regexp/substr, replacetext) Searches and replaces the regular expression (or sub string) portion (match) with the replaced text instead.
//replace(substr, replacetext)
var myString = '999 JavaScript Coders';
console.log(myString.replace(/JavaScript/i, "jQuery"));
//output: 999 jQuery Coders
//replace(regexp, replacetext)
var myString = '999 JavaScript Coders';
console.log(myString.replace(new RegExp( "999", "gi" ), "The"));
@unknownuser88
unknownuser88 / gist:8282856
Created January 6, 2014 13:25
search(regexp) Tests for a match in a string. It returns the index of the match, or -1 if not found.
//search(regexp)
var intRegex = /[0-9 -()+]+$/;
var myNumber = '999';
var isInt = myNumber.search(intRegex);
console.log(isInt);
//output: 0
@unknownuser88
unknownuser88 / gist:8282862
Created January 6, 2014 13:25
slice(start, [end]) Returns a substring of the string based on the “start” and “end” index arguments, NOT including the “end” index itself. “End” is optional, and if none is specified, the slice includes all characters from “start” to end of string.
//slice(start, end)
var text="excellent"
text.slice(0,4) //returns "exce"
text.slice(2,4) //returns "ce"
@unknownuser88
unknownuser88 / gist:8282866
Created January 6, 2014 13:25
split(delimiter, [limit]) Splits a string into many according to the specified delimiter, and returns an array containing each element. The optional “limit” is an integer that lets you specify the maximum number of elements to return.
//split(delimiter)
var message="Welcome to jQuery4u"
//word[0] contains "We"
//word[1] contains "lcome to jQuery4u"
var word=message.split("l")