How to create javascript array and object


In the Article we will learn about javascript Array and Object. We will learn , what is javascript array and object , Syntax of javascript array and object , Work of javascript array and object , etc . so lets start .

What is Array :

Array is type of variable , which store same and different data type of multiple variable. Array element start from 0 poisiton.

Syntax of Array :


var array_name = [item1, item2, ...];      



//define array with same data type of variable.



var language = ["PHP", "Javascript", "Jquery" , "HTML" , "CSS" , "AJAX"];





//define array with different data type of variable.



var item = ["PHP", 2, "Jquery" , 3 , "CSS" , 4];



//print array in console



conasole.log(item);



//pick the specific item from array

 console.log(item[0]);

 console.log(item[1]);

 console.log(item[2]);

What is Javascript Object :

A javaScript object is an entity having state and behavior (properties and method). For example: car, pen, bike, chair, glass, keyboard, monitor etc. JavaScript is an object-based language. Everything is an object in JavaScript..

Syntax of Javascript Object :


var person =  {f_name:"jitendra", l_name:"sahu", age:"23"};



//print the object

console.log(person)



//print the specific object element

console.log(person.f_name);

console.log(person.l_name)

console.log(person.age)





//define array of object

var persons = [ {f_name:"jitendra", l_name:"sahu", age:"23"} , {f_name:"jitendra", l_name:"sahu", age:"23"} ];



//print the array of object

console.log(persons);



//print the single object from array 

console.log(persons[0]);



//print the element of object from array of object

console.log(persons[0].f_name);

console.log(persons[0].l_name);

console.log(persons[0].age);