Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Data_Structures/Arrays/Basics/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// to declare and initialize an array, you can pass all the items in as a list
var food = ['bacon', 'corn', 'ham', 'sausage'];

// array values are retrieved by index, not name
// array values are retrieved by index (starting at 0), not name
console.log(food[2]);
console.log(food.length);

// loop over an array
// you can iterate over an array to access each individual element
for(var i=0; i<food.length; i++){
console.log(i, food[i]);
}

console.log('----------');

food.forEach(function (index, item) {
console.log(item, index);
});
Expand Down Expand Up @@ -44,6 +43,6 @@ console.log(food);

console.log('--------------------');

let numbers = [10, 32, 53, 99, 60];
var numbers = [10, 32, 53, 99, 60];
console.log(numbers.toString()); // comma separated list
console.log(numbers.join('~')); // to use a different separator