Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Learning JavaScript
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MohammadAli Keshavarz
Learning JavaScript
Commits
af8d2f4f
Commit
af8d2f4f
authored
Oct 10, 2019
by
MohammadAli Keshavarz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Objects and properties
parent
a94fbb77
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
1 deletion
+43
-1
script.js
script.js
+43
-1
No files found.
script.js
View file @
af8d2f4f
...
...
@@ -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
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment