When I looked at the source code before, I saw a method to determine whether a value is an array type, and I had a question in my mind.
Array.isarray (val) = array.isarray (val) = instanceof
toString.call(val) === "[object Array]"
Copy the code
Not clear why the author chose to use this way to judge the array type under the premise, I checked the data.
I found instanceof, isArray, and the methods mentioned in the source code.
Val instanceof Array // Does not support iframede window object Array creation Array array. isArray(val) // supports the aboveCopy the code
Check the Array type and array.isarray (val); What’s the difference?
The reason is that array. isArray is an ES5 method and does not support browsers below Internet Explorer 8Copy the code
Not wordy:
Which approach you adopt for your project is entirely dependent on your business needs.
If your project doesn’t need to be compatible with older browsers. So, array.isarray (val) is sufficient.
If your project can ignore array judgments of iframes, instanceof is fine.
If your project needs high enough requirements and is compatible with older browsers, you should use toString type judgment.
Thank you. Please give a thumbs up if you find anything. > _ <