SlideShare a Scribd company logo
1 of 13
Web Technologies – CS 382
Shehzad Aslam
Lecture 6
1 Hr
 Creating Objects in JavaScript
 Introduction to Data formats & JSON
 Representing Objects in JSON
 Representing Arrays in JSON
 Nested Objects or Arrays in JSON
 Object is any real world thing having
properties and behaviors
 We are going to see only properties not
behaviors
var objectname = {
property: value,
property:value
};
var fish= {
name: “tuna”,
weight:150,
color: “black & gray”
};
To access properties
 Dot notation
Objectname.property;
fish.name
 Map (associative array,
dictionary, hash table)
notation
Objectname[“property”];
fish[“name”]
 Create a Cat object
 name, food, age, color
 Create a chocolate object
 Company, price, packing
 Create a book object
 Title, author, pages, publisher
 Create a university object
 Name, location, number of campus, area, num_departments, head name
 Index based
var arrayname= new Array();
//then use push method
OR
var counting= [1,2,3,4];
var name = [“Ali”, “Umer”];
Or
var a = [“This”, 23, “2@df”];
To access Elements
arrayname[index];
counting[2];
name[1];
a[2];
var subject= {
session: 2014,
subjects: [
“Web Technology”,
“OOAD”,
“Computer Networks”
],
level: 6
};
Or could be nested objects, nested arrays or
any combination of both
To access OOAD
subject.subjects[1]
OR
Subject[“subjects”][1]
Why data? We have to provide or consume it.
 Can be CSV
 Tabular format may be comma separated
 XML
 Tag based just like HTML tags
 JSON
 Represent JavaScript objects
 Can Represent primitives, Object or Array
var counting= [1,2,3,4];
Will be
[
1,
2,
3,
4
]
var name = [“Ali”, “Umer”];
Will be
[
“Ali”,
“Umer”
]
Java
Script
Object
Notation
var objectname = {
property: value,
property:value
};
Will be
{
“property”:value,
“property”:value,
}
var fish= {
name: “tuna”,
weight:150,
color: “black & gray”
};
?
{
“name”: “tuna”,
“weight”:150,
“color”: “black & gray”
}
Just like so mixed objects
This data could be in new file with
json extension
 Create a Cat object
 name, food, age, color
 Represent In JSON
 Create a chocolate object
 Company, price, packing
 Represent In JSON
 Create a book object
 Title, author, pages, publisher
 Represent In JSON
 Create a university object
 Name, location, number of campus, area, num_departments, head name
 Represent In JSON
 Create a list of subject objects
 Each subject has code, title, credit hours, and teacher
 Represent In JSON
 Represent University Department in JavaScript Object & in
JSON
 Name, Head Name, Started, Programs offered (array), total students, total
faculty
 Create a university object
 Name, location, number of campus, area, num_departments, head name
 University has 3 departments
 Department of Business Management
 Department of Pharmacy
 Department of Mathematics
 Each department has above information given in example
 Represent in JSON
 Represent RCET in one Object
 Departments (array)
 Each department having name, hod name, faculty list (each faculty name, qualification),
no of students in each session
 Cafeteria (array) with list of food items each item having category, served
weight and price
 Playgrounds (array) with description, area
 Hostels (array) with name, warden, rooms (array) with each room resident
name
 Represent your time table in one object
 JSON validator
 Use http://jsonlint.com/ to validate your json
 Practical usage will be in next Lecture

More Related Content

More from maamir farooq (20)

J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheet
 
Assignment
AssignmentAssignment
Assignment
 
Java script summary
Java script summaryJava script summary
Java script summary
 
Lec 3
Lec 3Lec 3
Lec 3
 
Lec 2
Lec 2Lec 2
Lec 2
 
Lec 1
Lec 1Lec 1
Lec 1
 
Css summary
Css summaryCss summary
Css summary
 
Manual of image processing lab
Manual of image processing labManual of image processing lab
Manual of image processing lab
 
Session management
Session managementSession management
Session management
 
Data management
Data managementData management
Data management
 
Content provider
Content providerContent provider
Content provider
 
Android sq lite database tutorial
Android sq lite database tutorialAndroid sq lite database tutorial
Android sq lite database tutorial
 
5. content providers
5. content providers5. content providers
5. content providers
 
4.preference management
4.preference management 4.preference management
4.preference management
 
3. file external memory
3. file external memory3. file external memory
3. file external memory
 
2. file internal memory
2. file internal memory2. file internal memory
2. file internal memory
 
1. shared pref
1. shared pref1. shared pref
1. shared pref
 
Php sql-android
Php sql-androidPhp sql-android
Php sql-android
 
Networking
NetworkingNetworking
Networking
 
Alarms
AlarmsAlarms
Alarms
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

Lec 6

  • 1. Web Technologies – CS 382 Shehzad Aslam Lecture 6 1 Hr
  • 2.  Creating Objects in JavaScript  Introduction to Data formats & JSON  Representing Objects in JSON  Representing Arrays in JSON  Nested Objects or Arrays in JSON
  • 3.  Object is any real world thing having properties and behaviors  We are going to see only properties not behaviors var objectname = { property: value, property:value }; var fish= { name: “tuna”, weight:150, color: “black & gray” }; To access properties  Dot notation Objectname.property; fish.name  Map (associative array, dictionary, hash table) notation Objectname[“property”]; fish[“name”]
  • 4.  Create a Cat object  name, food, age, color  Create a chocolate object  Company, price, packing  Create a book object  Title, author, pages, publisher  Create a university object  Name, location, number of campus, area, num_departments, head name
  • 5.  Index based var arrayname= new Array(); //then use push method OR var counting= [1,2,3,4]; var name = [“Ali”, “Umer”]; Or var a = [“This”, 23, “2@df”]; To access Elements arrayname[index]; counting[2]; name[1]; a[2];
  • 6. var subject= { session: 2014, subjects: [ “Web Technology”, “OOAD”, “Computer Networks” ], level: 6 }; Or could be nested objects, nested arrays or any combination of both To access OOAD subject.subjects[1] OR Subject[“subjects”][1]
  • 7. Why data? We have to provide or consume it.  Can be CSV  Tabular format may be comma separated  XML  Tag based just like HTML tags  JSON  Represent JavaScript objects  Can Represent primitives, Object or Array
  • 8. var counting= [1,2,3,4]; Will be [ 1, 2, 3, 4 ] var name = [“Ali”, “Umer”]; Will be [ “Ali”, “Umer” ]
  • 9. Java Script Object Notation var objectname = { property: value, property:value }; Will be { “property”:value, “property”:value, } var fish= { name: “tuna”, weight:150, color: “black & gray” }; ? { “name”: “tuna”, “weight”:150, “color”: “black & gray” } Just like so mixed objects This data could be in new file with json extension
  • 10.  Create a Cat object  name, food, age, color  Represent In JSON  Create a chocolate object  Company, price, packing  Represent In JSON  Create a book object  Title, author, pages, publisher  Represent In JSON  Create a university object  Name, location, number of campus, area, num_departments, head name  Represent In JSON  Create a list of subject objects  Each subject has code, title, credit hours, and teacher  Represent In JSON
  • 11.  Represent University Department in JavaScript Object & in JSON  Name, Head Name, Started, Programs offered (array), total students, total faculty  Create a university object  Name, location, number of campus, area, num_departments, head name  University has 3 departments  Department of Business Management  Department of Pharmacy  Department of Mathematics  Each department has above information given in example  Represent in JSON
  • 12.  Represent RCET in one Object  Departments (array)  Each department having name, hod name, faculty list (each faculty name, qualification), no of students in each session  Cafeteria (array) with list of food items each item having category, served weight and price  Playgrounds (array) with description, area  Hostels (array) with name, warden, rooms (array) with each room resident name  Represent your time table in one object
  • 13.  JSON validator  Use http://jsonlint.com/ to validate your json  Practical usage will be in next Lecture