JS to determine whether the array is empty program code

Source: Internet
Author: User

Example 1

The code is as follows Copy Code

if (Tt==null | | tt== "") {
Alert ("Kong");
} else {
Alert ("Bukong");
}

Example 2

The code is as follows Copy Code

The var is = function (Obj,type) {
return (type = = "Null" && obj = = null) | |
(Type = = "Undefined" && obj = = void 0) | |
(Type = = "Number" && isfinite (obj)) | |
Object.prototype.toString.call (obj). Slice (8,-1) = = type;
}

Whether an element of an array is empty
1. If an array element does not exist: if (arr[x] = = undefined) determines
2. If the content in the element is null, it needs to be judged by the value of the array you are populating.

  code is as follows copy code

var B = new Array (1,null, ')
Console.log (b[1] = null);//fill element with null value
Console.log (b[2] = = ");//Fill element with empty (') value
Console.log (b[3] = = undefined); To determine an element that does not exist

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.