javascript study notes two: array objects and json objects in javascript

1. Array object: There are many ways to create a data object.
  Such as: var myArra1 = [3]; (this is the use of array literals), var myArra2 = new Array(3); (this is the use of the constructor of the array object to create an array object).

  The latter method creates an empty array of length 3.

2. Determine whether an object is an array:

  Array.isArray(new Array(3));//true;
  Array.isArray({length:1,'0':1,slice:function(){}});//以一个类似于数组的对象进行验证,返回false。用于验证的对象具有与数组类似的属性和方法更能说明此验证兼容性好
  有的浏览器框架不支持Array.isArray方法,此时可以:
  if(typeof Array.isArray() ==='undefined'){
	  Array.isArray = function(arg){
			return Object.prototype.toString.call(arg) === '[Object Array]';
	  }
  }

3. JSON object: json is a combination of an array and object literal representation methods (such as {"name":"jry","some":[1,2,3]}), the
  attributes in json must be enclosed in quotation marks (In the object literal, only when the attribute name is not a valid identifier, quotation marks are used, such as {"frist name":"jry"}),
  functions or regular expression literals cannot be used in json

Guess you like

Origin blog.csdn.net/nanxiaotiantian/article/details/20216407