JavaScript array
JavaScript Array.isArray
There is a PHP is_array function in PHP that can be used to determine whether a variable is a PHP array. Is there such a function in JavaScript? The answer is yes. In JavaScript version 1.8.5, a new function of Array.isArray has been added, which can be used to determine whether an object is a JavaScript Array array .
JavaScript Array.isArray basic syntax
Array.isArray( obj)
The obj in the syntax will be confirmed whether it is a JavaScript Array array , if it is an array, it will return TRUE, if it is not an array, it will return FALSE.
JavaScript Array.isArray example: return TRUE
Array.isArray(['a','b','c']);
Array.isArray([1]);
Array.isArray( new Array() );
Array.isArray([1]);
Array.isArray( new Array() );
The above obj is part of the JavaScript array , so TRUE will be returned through Array.isArray. The array is represented by using two square brackets to enclose the array key and value, whether it is an empty array or announcing a new array. As long as the attribute of obj belongs to the JavaScript array , Array.isArray will return TRUE.
JavaScript Array.isArray example: return FALSE
Array.isArray();
Array.isArray("Array");
Array.isArray(1);
Array.isArray({});
Array.isArray("Array");
Array.isArray(1);
Array.isArray({});
The obj in the example does not belong to the category of JavaScript array at all. The first line is not filled with obj, so it is completely impossible to judge. The second line only gives strings like Array, which is not equivalent to declaring an array in JavaScript. The third line is a number. 1 is not an array. The braces {} in the fourth line are not standard usage of arrays, so all of them will return FALSE.
Which browser versions support JavaScript Array.isArray?
As mentioned earlier, JavaScript Array.isArray must be supported in JavaScript version 1.8.5 or later. If the client browser is too old, it will lose its effect. At present, it seems that there is support for this. The browsers and versions of the functions are as follows. Of course, this table is for reference only. It is still subject to the actual status of the browser on the client side. If the JavaScript function is turned off on the client side, of course it cannot be used.
Chrome | FireFox | Internet Explorer | Safari | Opera |
5 | 4.2.0 | 9 | 5 | 10.5 |
Post a Comment
0 Comments