more
arrays
class overview
- Homework Solution
- Adding & Removing
- Array.filter()
- Array.map()
- Views Exercise
- Homework Overview
ADDING & REMOVING
- Add items to the end of an array with Array.push(value)
- Remove an item by using it's index and Array.splice(index, howMany)
var arr = [];
arr.push("trot");
arr.push("prance");
arr.push("jog");
//['trot', 'prance', 'jog']
//remove prance
arr.splice(1, 1);
//['trot', 'jog']
ARRAY.FILTER()
- Creates a new array filtered by a custom criteria
- First argument is a function to test each element. Returning true will include that element in that result.
//gets even numbers
[1,2,3,4,5].filter(function(value, index, arr) {
return value % 2 == 0;
});
//[2,4]
ARRAY.MAP()
- Creates a new array by calling the provided function on each value.
- First argument is the function to be called.
//add 5 to each number
[1,2,3,4,5].map(function(curVal, index, arr) {
return curVal + 5;
});
//[6,7,8,9,10]views exercise
- Make a page with multiple views
- Navigation should be via JavaScript
cool js thing for the day
Open API's
AJS Lecture 11: More Arrays
By Ryan Lewis
AJS Lecture 11: More Arrays
- 546