Today, I encountered a problem: how to change the height of the datagrid table (set to a fixed height) in easyui, read the documents for half a day, and check some information from the Internet, the easyui is really easy to use in some cases, and it is a little depressing. It is a little troublesome to adjust it at will.
If you can't do it, let it go first, and change your mood when you go home.
Yesterday in the implementation of the playback drag-and-drop track, the application of the array became a key step, so I specially checked some javascript operations on the array. Here we record:
The word "add, delete, modify, and query" is certainly not unfamiliar. Most of our work is on these operations, but these operations have a major premise: existence, there is an object for you to add, delete, modify, and query. If it does not exist, we will first create one:
1,Create
var a=new Array();var b=new Array(3);var c=new Array(['qwe',"12313",123]);var d=["asd","qwe","zxc"];
We usually create an array in the above four ways, and then
* Alert (a + "----------" + B + "---" + c + "--------" + d );
In this way, we can clearly see that,The first one is empty, while the second one has two commas (,), which indicates that three are empty, and the latter is normal output. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Refer to + KmFsZXJ0KHR5cGVvZihhKSYjNDM7 "----------" + typeof (B) + "---" + typeof (c) + "--------" + typeof (d, we have created an object successfully.
There are four methods in the creation process. Which one is better? We can't judge them. Different situations have their own merits. However, we need to pay special attention to one situation.
var test01=new Array(3);var test02=new Array([3]);
In fact, this is quite confusing, but the meaning of a square brackets is different,
The first one is to create an array with a length of 3, and the last one is to create an array with a length of 1 and a value of 3.If we put them together, we may all understand it, but we will give you one of them. If you do not take it carefully, it is very likely that something will go wrong.
On the other handNew Array ([5, 2]) and [5, 2]Are these two arrays the same and are answered in view.
2,View
Now that the object is successfully created, you can view the attributes or values of the object, or other attributes of the object. First, we know that the best way to view an array is to traverse it. The common syntax is:
For (var I = 0; I
Here we will not show them one by one, but only record a few confusing points:
* Alert (a [0] + "-----" + B [0] + "---" + c [0] + "-----" + d [0] + a [2] + "-----" + B [2] + "---" + c [2] + "-----" + d [2]); let's look at the output result.
Here we solve the problem created above. The new Array ([5, 2]) and [5, 2] are still different,The former indicates that an array is created, and the array contains an element. The latter indicates that two elements are created: "5" and "2"In fact, if we use the previous one to represent the latter, we should write it as: var e = new Array (["5'], [2],);
So I wrote such an output
var e=new Array(['qwe'],["12312"],[123]);var f=[["1","2"],["2","3"]]
* Alert (a [0] + "-----" + B [0] + "---" + c [0] + "-----" + d [0] + a [2] + "-----" + B [2] + "---" + c [2] + "-----" + d [2] + "---" + e [0] + "--" + f [0]); based on the above, you can guess what the result will be?
The principle is clearer, but I still have some doubts:
var d=["asd","qwe",123];var e=new Array('qwe',"12312",123);* ** If we output alert (e [2] + "---" + typeof [e [2] + "--" + d [2] + "---" + typeof (d [2]); why is the result 123, but one is an object and the other is a number? I still have some questions.
If var t = e [2] and type of (t) is output, it is also number. Why?
3,Delete
If there are more points in the above principle, remember more methods here.
. Pop ()This was applied yesterday,Delete the last element value of the array and return the value,Public object pop () {here is the last Implementation of deleting; return object}
Shift ()With the deletion of the last one, we will pay more attention to the first one. If there are headers and tails, this method is usedDelete the first element and return the value of this element.;
. Splice (here, num, newItem, newItem2 ,...)This method has parameters. The general meaning is to delete the nth to nth digits and return the deleted Value in the form of an array.The first parameter starts to be deleted at the beginning of the array. Here it starts from 0, and the second parameter is the number of digits.If the value is 0, no deletion is performed. If the value is 1, only one value is queried from the beginning of the number. If the value is followed by a parameter, then it should be added to the scope. Here we will first explain that after the previous operation, we will insert the following parameter in the Operation bit, that is, the new value.
4,Add
As mentioned aboveSpliceHere we should say that it has increased, and splice has increased to some extent,If 2nd parameters are set to 0 and 3rd or more parameters exist at the same time, they are increased. If 2nd parameters are not set to 0 and more parameters exist, that is, modifiedSo the modifications will not be discussed separately.
However. Push ()Add at the end of the array
Relative. Unshift ()It is added at the front end of the array. It corresponds to the deletion.
5,Sort
I have to say that this was a painful lesson. I used this method to sort the bubble sort before, but during the interview, I didn't even think of it. I thought it was an ugly reverse order. I thought it was so painful.
. Sort ()What a painful understanding
. Reverse ()In reverse order, I put the last part at the beginning, and finally reached the beginning. How painful is it to comprehend?
6. truncate, merge, and copy Arrays
. Slice (start, [end]),This application reminds me of subString (start, [end]). Here we generate a new one, a new one, and a new one.
. Concat ()Splicing, all are new ones. After splicing, new ones, new ones.
I have recorded so many useful operations for the time being, but I have not found many useful operations. Here I have attached a small knowledge:
There are six return values for typeof (): number/string/boolean/object/function/undefined (remember the difference between it and null)
The way of heaven is more than enough to make up for problems... who do you think of? Guo Jing, as long as you have an upward heart, you can always see the moment when the sun rises ....