JS: iterating over result of getElementsByClassName using Array.forEach

No. As specified in DOM4, it’s an HTMLCollection (in modern browsers, at least. Older browsers returned a NodeList). In all modern browsers (pretty much anything other IE <= 8), you can call Array’s forEach method, passing it the list of elements (be it HTMLCollection or NodeList) as the this value: If you’re in the happy position of being able to use ES6 (i.e. you can safely … Read more

How to get unique values in an array

Since I went on about it in the comments for @Rocket’s answer, I may as well provide an example that uses no libraries. This requires two new prototype functions, contains and unique For more reliability, you can replace contains with MDN’s indexOf shim and check if each element’s indexOf is equal to -1: documentation

ReactJS – .JS vs .JSX

There is none when it comes to file extensions. Your bundler/transpiler/whatever takes care of resolving what type of file contents there is. There are however some other considerations when deciding what to put into a .js or a .jsx file type. Since JSX isn’t standard JavaScript one could argue that anything that is not “plain” JavaScript should go into … Read more

NPM install fails with node-gyp

We are having problems running “npm install” on our project. A certain file cannot be found : It appears to be coming from the node-gyp module : c:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_lo ad_hook.c(13): fatal error C1083: Cannot open include file: ‘windows.h’: No suc h file or directory [D:\ngs-frontend-next\node_modules\browser-sync\node_module s\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil\buil d\binding.sln] This node-gyp seems to be a never ending … Read more