Arrays

  <html>

  <body>

    <button id="btnTry" onclick="myFavoriteActors();">All About my array</button>

    <br />   <br />

  <label id="lblActors"></label>

  <p>   Loop through the array:   </p>

  <p id="lblLoop"> </p>

 </body>

</html>


//Declaring the array

function myFavoriteActors() {

var Actors = ["Tiger", "Sushant", "Amir Khan", "Irfan Khan", "Ritesh Deshmukh"];

//Start with unordered list

text = "<ul>"

for (i=0; i<Actors.length; i++){

//Add Ordered List to the text

 text+= "<li>" + Actors[i] + "</i>";

}

//Close the unordered list

text += "<ul>";

document.getElementById("lblLoop").innerHTML = text;

var FirstItem = Actors[0];

var LastItem = Actors[Actors.length - 1]; 


//Find the length of the array, last item of the array, first item of the array

document.getElementById("lblActors").innerHTML = 

(("This is the length of my array " + Actors.length) + "<br />" + "<br />" + 

("This is the last item of my array " + LastItem) + "<br />" +"<br />"  +

("This is the first item of my array " + FirstItem));

}

No comments:

Post a Comment

Date Object

Purple: Style Blue: HTML Green: JavaScript  <!DOCTYPE html> <html> <style> #dates {   font-family: "Trebuchet MS...