Some processing methods of JavaScript array
Today's project, the use of a lot of array knowledge, here to do a record, learned a lot. a method for JavaScript to filter an empty array in an array.
var tagvalue = [1, "", ""];
var realvalue = [];
for (var i = 0; i < tagvalue.length i++) {
if (tagvalue[i]!= ') {
realvalue.push (tagvalue[i]);
}
;
Description:
Loops Tagvalue the array, if not NULL, inserts the value into the Realvalue array. Finally, we get the method of Realvalue two arrays with no null value.
Question details: A array contains all the strings, and b arrays have unknown strings. True if the string within a array contains each string in the B array, otherwise false.
As an example
var a = [1,2,3,4,5,6,7,8,9];
var B = [1,3];
At this point, take B and a to compare, the resulting value should be true
var b = [0,1]
//At this time, then false
Well, the method is:
Return A.filter (function (item) {return B.indexof (item)!==-1}). length = = = B.length
This is written by the master. Although after careful study to understand what is, but, still can not be very accurate description. Then, encapsulate a function to make it easier to use next time.
function Arr_contrast (a,b) {return
a.filter (function (item) {return B.indexof (item)!==-1}). length = = B.length
}
the application of JS multidimensional array
JS does not support multidimensional arrays, but you can simulate multidimensional arrays by including arrays in an array.
The Read method is arr[1][2] so. With two cycles, you can easily add values to a multidimensional array.
Let's write an example of a multidimensional array
<! DOCTYPE html>
combination of all the above knowledge points
Today did a demo, OK, not detailed description. The code is as follows
<! DOCTYPE html>