Commit af8d2f4f authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

Objects and properties

parent a94fbb77
......@@ -277,16 +277,25 @@ console.log(whatDoYouDo('retired', 'Mark'));
/*****************************
* Arrays
*/
/*
// Initialize new array
var names = ['John', 'Mark', 'Jane'];
var years = new Array(1990, 1969, 1948);
console.log(names[2]);
console.log(names.length);
var array = new Array() ;
console.log(array)
// Mutate array data
names[1] = 'Ben';
names[names.length] = 'Mary';
console.log(names);
names[7] = 'cristian'
console.log(names[6])
names.push('mahdi');
console.log(names.pop())
names.pop()
console.log(names)
// Different data types
var john = ['John', 'Smith', 1990, 'designer', false];
john.push('blue');
......@@ -299,4 +308,37 @@ console.log(john);
console.log(john.indexOf(23));
var isDesigner = john.indexOf('designer') === -1 ? 'John is NOT a designer' : 'John IS a designer';
console.log(isDesigner);
*/
/*****************************
* Objects and properties
*/
// Object literal
var john = {
firstName: 'John',
lastName: 'Smith',
birthYear: 1990,
family: ['Jane', 'Mark', 'Bob', 'Emily'],
job: 'teacher',
isMarried: false
};
console.log(john.firstName);
console.log(john['lastName']);
var x = 'birthYear';
console.log(john[x]);
john.job = 'designer';
john['isMarried'] = true;
console.log(john);
// new Object syntax
var jane = new Object();
jane.firstName = 'Jane';
jane.birthYear = 1969;
jane['lastName'] = 'Smith';
console.log(jane);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment