Created
November 8, 2015 18:29
-
-
Save anonymous/c9ff22330f910ad836bf to your computer and use it in GitHub Desktop.
JavaScript Filter, Map and ForEach Example // source http://jsbin.com/nimatu
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 ng-app="app"> | |
<head> | |
<script src="https://cdn.rawgit.com/lodash/lodash/3.0.1/lodash.min.js"></script> | |
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JavaScript Filter, Map and ForEach Example</title> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="content" ng-controller="MainCtrl"> | |
<ul ng-repeat="student in students"> | |
<li> <h1>{{ student }}</h1></li> | |
</ul> | |
</div> | |
</div> | |
<script id="jsbin-javascript"> | |
console.clear(); | |
var app = angular.module('app', []); | |
app.controller('MainCtrl', function($scope, $rootScope) { | |
$scope.students = []; | |
var students = [ | |
{ name: 'John Connor', score: 76, subject: 'biology' }, | |
{ name: 'Mary Jones', score: 62, subject: 'history' }, | |
{ name: 'James Young', score: 42, subject: 'physics' }, | |
{ name: 'Susan Torpe', score: 46, subject: 'maths' } | |
]; | |
var failed = students.filter(function(student) { | |
// filter students with a score less than 50% | |
return student.score < 50; | |
}).map(function(student) { | |
// find out which subjects the students failed | |
return student.name; | |
}).forEach(function(student) { | |
// print the names of the students that failed | |
console.log(student); | |
$scope.students.push(student); | |
}); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">console.clear(); | |
var app = angular.module('app', []); | |
app.controller('MainCtrl', function($scope, $rootScope) { | |
$scope.students = []; | |
var students = [ | |
{ name: 'John Connor', score: 76, subject: 'biology' }, | |
{ name: 'Mary Jones', score: 62, subject: 'history' }, | |
{ name: 'James Young', score: 42, subject: 'physics' }, | |
{ name: 'Susan Torpe', score: 46, subject: 'maths' } | |
]; | |
var failed = students.filter(function(student) { | |
// filter students with a score less than 50% | |
return student.score < 50; | |
}).map(function(student) { | |
// find out which subjects the students failed | |
return student.name; | |
}).forEach(function(student) { | |
// print the names of the students that failed | |
console.log(student); | |
$scope.students.push(student); | |
}); | |
});</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
console.clear(); | |
var app = angular.module('app', []); | |
app.controller('MainCtrl', function($scope, $rootScope) { | |
$scope.students = []; | |
var students = [ | |
{ name: 'John Connor', score: 76, subject: 'biology' }, | |
{ name: 'Mary Jones', score: 62, subject: 'history' }, | |
{ name: 'James Young', score: 42, subject: 'physics' }, | |
{ name: 'Susan Torpe', score: 46, subject: 'maths' } | |
]; | |
var failed = students.filter(function(student) { | |
// filter students with a score less than 50% | |
return student.score < 50; | |
}).map(function(student) { | |
// find out which subjects the students failed | |
return student.name; | |
}).forEach(function(student) { | |
// print the names of the students that failed | |
console.log(student); | |
$scope.students.push(student); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment