Skip to content

Instantly share code, notes, and snippets.

@dmdevoss
Created May 27, 2014 14:47
Show Gist options
  • Select an option

  • Save dmdevoss/ae4ed6e2fa94c9ccd62b to your computer and use it in GitHub Desktop.

Select an option

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.
$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