Array basics
Based on learnrx: http://reactivex.io/learnrx/
by Jason Aden
JavaScript
console.clear();
var names = ["Ben", "Jafar", "Matt", "Priya", "Brian"];
var newReleases = [
{
"id": 70111470,
"title": "Die Hard",
"boxart": "http://cdn-0.nflximg.com/images/2891/DieHard.jpg",
"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
"rating": [4.0],
"bookmark": []
},
{
"id": 654356453,
"title": "Bad Boys",
"boxart": "http://cdn-0.nflximg.com/images/2891/BadBoys.jpg",
"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
"rating": [5.0],
"bookmark": [{ id:432534, time:65876586 }]
},
{
"id": 65432445,
"title": "The Chamber",
"boxart": "http://cdn-0.nflximg.com/images/2891/TheChamber.jpg",
"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
"rating": [4.0],
"bookmark": []
},
{
"id": 675465,
"title": "Fracture",
"boxart": "http://cdn-0.nflximg.com/images/2891/Fracture.jpg",
"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
"rating": [5.0],
"bookmark": [{ id:432534, time:65876586 }]
}
];
/******************* FOR LOOP *******************/
// EXERCISE 1. Print all the names in an array using for loop
function printNames (names) {
for (var i = 0 ; i < names.length ; i++) {
console.log(names[i]);
}
}
// printNames(names)
/******************* .forEach(cb) *******************
Arrays have a 'forEach' method that iterates through each element
of the array, calling the callback parameter passed in.
*/
// EXERCISE 2. Use forEach to print all the names in an array
names.forEach(function (val, idx) {
console.log(val, idx)
})
/******************* PROJECTIONS *******************
Applying a function to a value and creating a new value is called
a projection. To project one array into another, we apply a
projection function to each item in the array and collect the
results in a...