Declaration and application of js array (primary understanding)

1: The role of the array: only the batch of data needs to use the array declaration

Two: How to declare an array:

1: A quick way to declare an array

var array name = [element 1, element 2, . . ];

example:

var names = ["name", "age", "grade"];

var tems=["cab","10","11,true];

var arrs = {

             ["111","222"],

             ["aaa","bbbb"],

             ["333","ccc"]

};

alert(arrs[1][1]);

2. Declaration method:

Use Array objects

var arr = new Array("member", "member n");

var str="abc";

var str=new string("abc")

for...in: Use the for...in statement to loop through the elements in the output array concat(): concat() merges two arrays.

One: DOM

effect:

Dom(Documnet object Model)

1:document document html xml file (markup language)

<body>

   <div>

               <a>www</a>

   </div>

</body>

2: object object (the object that the html element is converted into (js object))

If you use js to manipulate documents, you need to choose to convert the html document structure into js objects

a. Operational properties

b. Operation content

innerText(IE) textContent(FF)

innerHTML

outerText

outerHTML

Form:

      value

   

c. Operation style

aobj.style.backgroundColor="red";

aobj.style.fontSize="3cm";

classname

aobj.classname="test";

aobj.classname+="demo";

aobj.calssName=""

 With the above three points of operation, first convert it into an object

convert to object

1: tagname (multiple), id (unique), name (multiple)

Three methods in document

var objs=document.getElementByTagName("div");

var objs=document.getElementById("one");

var objs=document.getElementByName("two");


Array exercise:

<script>
var mycars = new Array()
mycars[0] = "Saab"
mycars[1] = "Volvo"
mycars[2] = "BMW"


for (i=0;i<mycars.length;i++)
{
document.write(mycars[i] + "<br />")
}
</script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325764712&siteId=291194637
Recommended