Skip to content

Instantly share code, notes, and snippets.

View csdear's full-sized avatar

Stuart Dear csdear

View GitHub Profile
@csdear
csdear / Simple Array : IndexOf.js
Created March 16, 2016 14:48
Simple Array IndexOf
var fruits = ['banana', 'orange', 'apple', 'mango'];
var wheresTheApple = fruits.indexOf("apple");
>wheresTheApple
<2
//This is case sensitive. if not found retuns -1
var wheresTheApple = fruits.indexOf("Apple");
undefined
@csdear
csdear / SIMPLE JS OBJECT.js
Created March 11, 2016 18:14
A SIMPLE JS OBJECT AND ACCESS VIA DOT NOTATION. • An object, person1, with two property slots and one method slot.
//testable via console
var person1 = {
lastName : "Dear",
firstName : "Stuart",
getFullName : function () {
return this.firstName + " " + this.lastName;
}
};
@csdear
csdear / Javascript DATE and TIME functions.js
Last active March 15, 2016 20:19
Javascript DATE and TIME functions : Creation and Conversion
var myNewDate = new Date(Date());
//Output : undefined
myNewDate
//Output : Thu Mar 10 2016 09:57:10 GMT-0600 (Central Standard Time)
myNewDate instanceof Date;
//Output : true
var myNewDateString = myNewDate.toISOString();
//Output : undefined
myNewDateString
//Output : "2016-03-10T15:57:10.000Z"
@csdear
csdear / .extend JQuery function.js
Created March 9, 2016 21:44
jquery .Extend will merge the contents of two or more objects into the first object
// This will merge the contents of two or more objects into the first object
// I think it can also be said, can be merged aggregated into a entirely new object.
//target, the object will be extended, have the new properties.
//HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
@csdear
csdear / .each jQuery function.js
Last active March 9, 2016 21:45
.each jQuery function iterates through an array or an object
//consolable
//1. Simple usage, on an array
// basically pass in an array, .each will iterate over each element in the array.
// here the output is the index (0,1,3), then the value ( 52, 97 )
//This can get more sophisticated when passing in data from a Json file.
$.each([ 52, 97 ], function( index, value ) {
alert( index + ": " + value );
});
@csdear
csdear / Array Loop Through using For(ICU).js
Created March 7, 2016 22:41
Array Loop Through using For(ICU)
/*
1. Store a open index var
2. You can create other vars to hold html tags to be used in final formatting
3. Create the array. here we have one with 4 elements
4. evoke your for loop
- I : create your sentry variable, use the same open index var you created
at step 1.
- C : While the index is less than the length property of fruits array,
execute the block
@csdear
csdear / Arrays JScript.js
Last active March 7, 2016 22:25
Arrays JScript
//1. Simple array and test
// isAarray method will help you tell if it is actually an array.typeof only returns 'object'
<!DOCTYPE html>
<html>
<body>
<p>The new ECMASCRIPT 5 method isArray returns true when used on an array.</p>
<p id="demo"></p>
@csdear
csdear / While - do Loop.js
Last active March 7, 2016 20:35
While Loop and Do
/*
The while statement performs a simple loop. If the expression is falsy, then the loop will break.
While the expression is truthy, the block will be executed.
*/
<!DOCTYPE html>
<html>
<body>
@csdear
csdear / Switch jScript.js
Created March 7, 2016 18:06
Switch jScript
//basic switch case statement.
<!DOCTYPE html>
<html>
<body>
<button onclick="whatDayIsIt()">What day is it? </button>
<p id="demo"></p>
<script>
function whatDayIsIt() {
@csdear
csdear / Basic jScript Web Scaffold.js
Created March 7, 2016 17:28
Basic jScript Web Scaffold.js
/*
A basic javascript scaffold template, considering input, the function and output.
<<>> are variable areas.
*/
<!DOCTYPE html>
<html>
<body>