File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- var food = [ 'bacon' , 'corn' , 'sausage' ] ;
1+ var food = [ 'bacon' , 'corn' , 'ham' , ' sausage'] ;
22
33// array values are retrieved by index, not name
44console . log ( food [ 2 ] ) ;
@@ -17,24 +17,26 @@ food.forEach(function (index, item) {
1717
1818console . log ( '----------' ) ;
1919
20- // add new items to an array
20+ // add new items to end of array
2121food . push ( 'tuna' ) ;
2222console . log ( food ) ;
2323
24- // remove item from the end of an array
24+ // remove item from the end of array
2525var lastItem = food . pop ( ) ;
2626console . log ( lastItem ) ;
2727console . log ( food ) ;
2828
29- // remove item from the beginning of an array
30- var firstItem = food . shift ( ) ;
31- console . log ( firstItem ) ;
32- console . log ( food ) ;
29+ console . log ( '----------' ) ;
3330
3431// add item to beginning of an array
3532food . unshift ( 'apples' ) ;
3633console . log ( food ) ;
3734
35+ // remove item from the beginning of an array
36+ var firstItem = food . shift ( ) ;
37+ console . log ( firstItem ) ;
38+ console . log ( food ) ;
39+
3840// remove item by index position
3941var pos = 1 ;
4042food . splice ( pos , 1 ) ;
You can’t perform that action at this time.
0 commit comments