Arrays and Objects in JS

I Reviewing Arrays
i. You know this! 1/17

var list = [2, 4, 6, "make", "list"]

ii. Access by offset 2/17

var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
console.log(languages[2]);

iii. Array properties 3/17

var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
console.log(languages.length);

iv. Iterating over an array 4/17

var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
for (var i = 0; i < languages.length; i++) {
    console.log(languages[i]);
}

II More with Arrays
i. Heterogeneous arrays 5/17

var myArray = [2, false, "my"];

ii. Arrays of arrays 6/17

var newArray = [[1,2,3],["i", "love", "me"], [3,4,5]]

iii. Jagged arrays 7/17

var jagged = [[1,2,3],["red","blue"]]

iv. Mid-lesson breather 8/17
Save and Submit!

III Introduction to Objects
i. Nouns and verbs together 9/17

var phonebookEntry = {};

phonebookEntry.name = 'Oxnard Montalvo';
phonebookEntry.number = '(555) 555-5555';
phonebookEntry.phone = function() {
  console.log('Calling ' + this.name + ' at ' + this.number + '...');
};

phonebookEntry.phone();

ii. Object syntax 10/17

var me = {
    name: 'Sunakshi',
    age: 23
};

iii. Creating a new object 11/17

var me = new Object();
me.name = "Sunakshi";
me.age = 23;

iv. Practice makes perfect 12/17

var object1 = new Object();
object1.color = 'blue';
var object2 = new Object();
object2.price = 32;
var object3 = new Object();
object3.size = 'huge';

v. Review 13/17
Save and Submit

IV Review
i. Heterogeneous arrays 14/17

var myObj = {
    color: 'red',
    size: 15
};   
var myArray = [2, false, "man", myObj] 

ii. Multidimensional arrays 15/17

var newArray = {
    color: 'red',
    size: 15
};
    
var newArray = [[2, false], [myObj]]

iii. Editing an existing object 16/17

var myObject = {
  name: 'Eduardo',
  type: 'Most excellent',
  interests: ['dancing','coding']  
};

iv. Creating your own objects 17/17

 var myOwnObject = {
    properties: ['small','narrow','black'],
    flower: 'jasmine',
    size: 14,
    bool: true
    
};
Advertisements

One thought on “Arrays and Objects in JS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s