This is a simple loop to check for a partial key in an Array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * Extend the Array object * @param searchValue is the string to search for * @returns Returns all matches */ Array.prototype.searchFor = function(searchValue) { var pattern = new RegExp('^'+searchValue+''); var matches = []; for (var key in this) { if (pattern.test(key)) { matches.push(key); } } return matches; }; |
Use it like this
1 2 3 |
var searchValue = "checkForMe"; var searchArray = []; var matches = searchArray.searchFor(searchValue); |
I am using something similar to look though a huge word/key index and output matching keys that link to a Data object.
I am a full-stack developer. My expertise include:
I love programming, design and know my way around server architecture as well. I would never feel complete, with one of these missing.
I have a broad range of interests, that’s why I constantly dive into new technologies and expand my knowledge where ever required. Technologies are evolving fast and I enjoy using the latest.
Apart from that, I am a peace loving guy who tries to have people around him that think the same. I truly believe in the principle: “If you help someone, someone will help you, when you need it."