How do I test for an empty JavaScript object?
Note, though, that this creates an unnecessary array (the return value of keys). Pre-ECMA 5: jQuery: lodash: Underscore: Hoek ExtJS AngularJS (version 1) Ramda
Note, though, that this creates an unnecessary array (the return value of keys). Pre-ECMA 5: jQuery: lodash: Underscore: Hoek ExtJS AngularJS (version 1) Ramda
Use the find() method: From MDN: The find() method returns the first value in the array, if an element in the array satisfies the provided testing function. Otherwise undefined is returned. If you want to find its index instead, use findIndex(): From MDN: The findIndex() method returns the index of the first element in the … Read more
Modern browsers have Array#includes, which does exactly that and is widely supported by everyone except IE: Run code snippet You can also use Array#indexOf, which is less direct, but doesn’t require polyfills for outdated browsers. Run code snippet Many frameworks also offer similar methods: jQuery: $.inArray(value, array, [fromIndex]) Underscore.js: _.contains(array, value) (also aliased as _.include and _.includes) Dojo Toolkit: dojo.indexOf(array, value, [fromIndex, findLast]) Prototype: array.indexOf(value) MooTools: array.indexOf(value) MochiKit: findValue(array, value) MS … Read more
Nobody seems to be explaining the difference between an array and an object. [] is declaring an array. {} is declaring an object. An array has all the features of an object with additional features (you can think of an array like a sub-class of an object) where additional methods and capabilities are added in … Read more