javascript objects vs arrays vs JSON Data Types

javascript objects vs arrays vs JSON Data Types

Today, We want to share with you javascript objects vs arrays vs JSON Data Types.
In this post we will show you JavaScript has several list data types: javascript objects vs arrays vs JSON, hear for Understanding Data Types in JavaScript we will give you demo and example for implement.
In this post, we will learn about JavaScript data types and data structures with an example.

1st : Number

[html]
5
575
-5784
523.25
[/html]

2nd : String

[html]
“Hi angularking”
“websitename:\nmy first website is Pakainfo.com”
[/html]

3rd : Boolean

[html]
true
false
[/html]

4th : Array

[html]
[9,8,2,5,6,0,6,2,4,5]
[]
[“j”, “a”, 9898]
[“j”, “a”, 9898, [6,7,8,9,5,2,1]]
[/html]

5th : Object

[html]
{}
{n: 10}
{salesorderlist: [9,9,7,4,8,4,0,4,0,2], studlist: [9,8,5,6,8,9,8,5,6,2,0]}
{myinfo: {username: ‘admin’, age: 50}, yourinfo: {yname: ‘userfaran’, age: 58}}
[/html]

simple You use the special char{ braces } (curly braces)to declare(init) an object literal in javascript.
and then second things , You use the special char [ square brackets ] (square braces) to declare(init) an array literal in javascript.

Objects are list of collections of key index name value(Like “name”:”adminnglivefree”) pairs.
JSON is a subset-of-the-object literal notation of JavaScript.

Example of an array of strings in javascript:

[html]
var a = [ “virat”, “yuvraj”, “dhoni” ];
[/html]

Example of a simple object of players in javascript :

[html]
var playerObject = {
playername: ‘yashraj’,
playerage: 29,
playerhometown: ‘kalavad’
};
[/html]

JSON is a simple data representation of the data structure,
It is not an any object data or an array data.

[html]
[9,6,3,8,1,4,5,7,8,9,9,2,5,0,2,5,8,9]
[/html]

Example of array.

[html]
{“salesordername”:”virat kohali”}
[/html]

Example of object.

[html]
[
{“salesuser_id”:1035,”username”:”jonash”},
{“salesuser_id”:2087,”username”:”deepakful”}
]
[/html]

Example : array of objects.

[html]
{
“languages”:
[
{“langid”:9852,”langname”:”magento”},
{“langid”:9853,”langname”:”laravel”}
],
“cources”:
[
{“coid”:8758,”coursename”:”MCA”},
{“coid”:8789,”coursename”:”BCA”}
]
}
[/html]

difference between json array and json object

simple meaning of JSON object is a single item value whereas list of JSON array
(it can be collection of values),and it is a data collection of objects.

[html]

JSON object :

var docters = {drfirstusername: ‘dhameliyaravi’, usersirname: ‘M’};

JSON array:

var docters = [{drfirstusername: ‘dhameliyaravi’, usersirname: ‘M’}, {drfirstusername: ‘Quora’, usersirname: ”}];

//Example of JSON:
{ “profname”: “parag shukla” }

//Example of Object literal:
var objectname= { profname: “parag shukla” };

[/html]

Invalid Json Example

[html]

//Example of Invalid JSON:
{ “profname”: ‘parag shukla’ }

//Example of Invalid JSON:
{ “profname”: 0xFF }

[/html]

Basic Note :

JSON is limited and (Data structure functionality) in that it cannot any store functions or
The only values list of data types:

1st : objects (literals)
2nd : arrays
3rd : numbers
4th : booleans
5th : strings
6th : nulls

Leave a Comment