This file contains hidden or 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
| var names = ['adam', 'brian', 'charles']; | |
| names.forEach (function (name) { | |
| console.log (name); | |
| }); | |
| // adam, brian, charles |
This file contains hidden or 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
| var names = ['adam', 'brian', 'charles']; | |
| function printsName (name) { | |
| console.log (name); | |
| } | |
| names.forEach (printName); |
This file contains hidden or 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
| var channels = ["A", "B", "C"]; | |
| channels.forEach(function(channel) { | |
| channels.push("D"); // this item will be ignored | |
| console.log(channel); | |
| }) |
This file contains hidden or 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
| var channels = ["A", "B", "C"]; | |
| channels.forEach (function (channel) { | |
| channels.push ("D"); // this item will be ignored | |
| console.log (channel); | |
| }) | |
| console.log (channels); | |
| // ['A', 'B', 'C', 'D', 'D', 'D'] |
This file contains hidden or 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
| var numbers = [1,2,3]; | |
| double var = []; | |
| for (var i = 0; i <numbers.length; i ++) { | |
| double.push (numbers [i] * 2); | |
| } | |
| console.log (numbers); // [1,2,3] | |
| console.log (double); // [2,4,6] |
This file contains hidden or 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
| var numbers = [1,2,3]; | |
| double var = numbers.map (function (number) { | |
| return number * 2; | |
| }); | |
| console.log (numbers); // [1,2,3] | |
| console.log (double); // [2,4,6] |
This file contains hidden or 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
| var students = [ | |
| {name: 'adam', age: 15}, | |
| {name: 'brian', age: 18}, | |
| {name: 'charles', age: 20} | |
| ]; | |
| varLarest students = []; | |
| for (var i = 0; i <students.length; i ++) { | |
| if (students [i] age> = 18) { | |
| MajorStudents.push (students [i]); | |
| } |
This file contains hidden or 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
| var students = [ | |
| {name: 'adam', age: 15}, | |
| {name: 'brian', age: 18}, | |
| {name: 'charles', age: 20} | |
| ]; | |
| varLarest students = students.filter (function (student) { | |
| return student.ity> = 18; | |
| }); | |
| console.log (MajorStudents); | |
| // [{name: 'adam', age: 18}, {name: 'brian', age: 20}] |
This file contains hidden or 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
| var students = [ | |
| {name: 'adam'}, | |
| {name: 'brian'}, | |
| {name: 'charles'} | |
| ]; | |
| var student; | |
| for (var i = 0; i <students.length; i ++) { | |
| if (students [i] .name === 'brian') { | |
| student = students [i]; | |
| break; // avoid scrolling through the rest of the list |
This file contains hidden or 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
| var students = [ | |
| {name: 'adam'}, | |
| {name: 'brian'}, | |
| {name: 'charles'} | |
| ]; | |
| var student = students.find (function (student) { | |
| return student.name === 'brian'; | |
| }); | |
| console.log (student); // {"name": "brian"} |