Javascript

Once after page loads, your DOM is ready to load the functions

$(document).ready(function(){
  myFunction();
});

function myFunction(){
  alert("Hello World");
}

var carsArray = ["Ford", "Maruthi", "Benz", "Audi"];
carsArray.sort(); //to sort the array
//To find its value, then seach by its index
carsArray[0] means you will get its value as Audi

what is JSON array

JSON array is array with key and value pair or Object inside an Array. JSON array most popular data format or data model used in current market.
var carJsonArra = [{"Teja":29},{"Meena":24},{"Mouni":28}];
carJsonArra[0]// means it gives 0th index value as {"Teja":29} which is a object inside an array
carJsonArra.length // gives length of the array means count of objects inside array

//Loop the array in javascript

var myData = [{Name: 'Teja'},{Name: 'Mouni'},{Name: 'Meena'}]
for(var i=0;i<myData.length;i++){
console.log("Index value: "+i+". The Name is "+myData[i].Name);
}

//Object representation

var myObj = {"Name": "Teja","Age":29};
//To get the Name from object
myObj["Name"];//output is Teja

//To push the value to the array

myData.push({"Name":"Gangadhar"});
//then see the myData array now in console

[{Name: 'Teja'},{Name: 'Mouni'},{Name: 'Meena'},{"Name":"Gangadhar"}];

Comments