/ Published in: JavaScript
                    
                                        Detect if an object exists in an array or detect existance of a key in an object
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 /* Author: Francois Lafortune (@quickredfox) License: WTFPL Description: Detect if an object exists in an array or detect existance of a key in an object Example: (code) var myArray = [ 'red', 'green', 'blue' ]; Detect.inArray( 'red' , myArray) // true Detect.inArray( 'brown' , myArray) // false var myObject = {color: 'blue' }; Detect.inObject('color',myObject) // true Detect.inObject('taste',myObject) // false (end) */ var Detect = (function() { var Detect = { inArray: function(key, array) { return (key in array); }, inObject: function(key, object) { return (key.toString() in object) } } return Detect; })();
Comments
                    Subscribe to comments
                
                