Some processing methods of JavaScript array __javascript

Source: Internet
Author: User
Tags javascript array
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> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.