Created
May 27, 2014 14:47
-
-
Save dmdevoss/ae4ed6e2fa94c9ccd62b to your computer and use it in GitHub Desktop.
Searches an array of meta values, if it doesn't find it, it creates a new json object, pushes it on and returns its index.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $scope.arraySearch = function (array, key) { | |
| for (var i = array.length - 1; i >= 0; i--) { | |
| console.log(array[i].meta_key); | |
| if (array[i].meta_key === key){ | |
| console.log("Found " + key + " at " + i); | |
| return i; | |
| } | |
| }; | |
| console.log("Could not find " + key); | |
| var newJson = { | |
| "meta_key": key, | |
| "meta_value": "no" | |
| } | |
| array.push(newJson); | |
| return array.length - 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment