Example parsing for use in JavaScript for

Source: Internet
Author: User

  Use JS friends for the in is not unfamiliar with it, the following examples for you to introduce their specific use of the method

for (var i=0;i<len;i++) Such usage can generally be replaced with for.   For example, the:  code is as follows: var a = ["A", "B", "C"];  for (Var el in a) {  alert (a[el)); }    This is the name of the poor name There are elements, of course above This example can be used   code as follows: for (var i=0,len=a.length;i<len;i++) {  alert (a[i)); }    This is a way of looping through the list, but sometimes this is not necessarily the way it works.   For example, the:  code is as follows: var a = {"A": 1, "second": 2, "third":3};    this time can only use for to the poor lift.     Whether an object can be used for in-exhaustive, we can judge by the propertyIsEnumerable property, stating the following:  propertyisenumerable properties   return Boolean Value that indicates whether the specified property is part of an object and whether the property is enumerable.   Copy code code as follows: Object.propertyisenumerable (proname)     parameter   object  required option. An object.     proname  required options. A string value for a property name.     Description   If Proname exists in object and you can use a for ... The propertyIsEnumerable property returns True if the in loop is a poor lift. If object does not have the specified property or the specified property is not enumerable, then the propertyIsEnumerable property returns False. Typically, predefined properties are not enumerable, and user-defined attributes can always be enumerated. The   propertyisenumerable attribute does not consider objects in the prototype chain.    
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.