Created
December 3, 2016 01:12
-
-
Save anonymous/3a0b4bca693b085bf30f5bf2ac98c93f to your computer and use it in GitHub Desktop.
Arrays Array studies // source https://jsbin.com/dikixab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Array studies"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Arrays</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// -----Arrays----- // | |
/* Arrays are list-like objects with a large number of mutational and accessible | |
methods. They can be assigned to variables and are enclosed with squar brackets: */ | |
"use strict"; | |
var exArray = ["I'm element 0", "I'm element 1", "Care to guess?"]; | |
/* As the example demonstrates, arrays are zero-based indexed, and elements can | |
be accessed by referring to its index: */ | |
console.log(exArray[1]); // logs "I'm element 1" | |
/* Dot-notation syntax will return an error: */ | |
// console.log(exArray.1); // ERROR, or just won't log anything | |
/* While technically Javascript considers arrays as objects, it is common to need | |
to check if an object is an array; the following method will check and return | |
a boolean value: */ | |
console.log(Array.isArray(exArray)); // true | |
var notArray = {}; | |
console.log(Array.isArray(notArray)); // false | |
/* The .length method will return the numeric length of the array's elements: */ | |
console.log(exArray.length); // logs 3 | |
/* Not to be confused with each element's zero-based index, .length begins counting | |
at 1. The previous example counts three elements and logs "3." This method can | |
also be used to log the very last element on an array no matter how long it is.*/ | |
console.log(exArray[exArray.length - 1]); // logs "Care to guess?" | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// -----Arrays----- // | |
/* Arrays are list-like objects with a large number of mutational and accessible | |
methods. They can be assigned to variables and are enclosed with squar brackets: */ | |
var exArray = ["I'm element 0", "I'm element 1", "Care to guess?"]; | |
/* As the example demonstrates, arrays are zero-based indexed, and elements can | |
be accessed by referring to its index: */ | |
console.log(exArray[1]); // logs "I'm element 1" | |
/* Dot-notation syntax will return an error: */ | |
// console.log(exArray.1); // ERROR, or just won't log anything | |
/* While technically Javascript considers arrays as objects, it is common to need | |
to check if an object is an array; the following method will check and return | |
a boolean value: */ | |
console.log(Array.isArray(exArray)); // true | |
var notArray = {}; | |
console.log(Array.isArray(notArray)); // false | |
/* The .length method will return the numeric length of the array's elements: */ | |
console.log(exArray.length); // logs 3 | |
/* Not to be confused with each element's zero-based index, .length begins counting | |
at 1. The previous example counts three elements and logs "3." This method can | |
also be used to log the very last element on an array no matter how long it is.*/ | |
console.log(exArray[exArray.length - 1]); // logs "Care to guess?"</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -----Arrays----- // | |
/* Arrays are list-like objects with a large number of mutational and accessible | |
methods. They can be assigned to variables and are enclosed with squar brackets: */ | |
"use strict"; | |
var exArray = ["I'm element 0", "I'm element 1", "Care to guess?"]; | |
/* As the example demonstrates, arrays are zero-based indexed, and elements can | |
be accessed by referring to its index: */ | |
console.log(exArray[1]); // logs "I'm element 1" | |
/* Dot-notation syntax will return an error: */ | |
// console.log(exArray.1); // ERROR, or just won't log anything | |
/* While technically Javascript considers arrays as objects, it is common to need | |
to check if an object is an array; the following method will check and return | |
a boolean value: */ | |
console.log(Array.isArray(exArray)); // true | |
var notArray = {}; | |
console.log(Array.isArray(notArray)); // false | |
/* The .length method will return the numeric length of the array's elements: */ | |
console.log(exArray.length); // logs 3 | |
/* Not to be confused with each element's zero-based index, .length begins counting | |
at 1. The previous example counts three elements and logs "3." This method can | |
also be used to log the very last element on an array no matter how long it is.*/ | |
console.log(exArray[exArray.length - 1]); // logs "Care to guess?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment