Search code examples
javascripttyped-arrays

How to check if javascript typed arrays are supported?


Would like to test with javascript if browser support typed array http://caniuse.com/#feat=typedarrays

i tryed this but seems not the good way because some browser have just a partial support..:

if(window.ArrayBuffer){alert('typed array supported')}

Solution

  • It seems some browsers (IE10) doesn't support Uint8ClampedArray, and if that is a feature you intend to use, you can just check for it

    if ( 'Uint8ClampedArray' in window ) { ...
    

    If the check returns false, typed arrays and/or clamped arrays are not supported.
    If you don't need Uint8ClampedArray, you can stick with what you've got, personally I like to use in

    if ( 'ArrayBuffer' in window ) { ...