I am trying to find the results for a huge array (7000+ items) and for some reason, the script I used before for another project keeps returning false, or I’m probably forgetting something.
I am trying to sort through an array and find two items that’s listed in a variable. Here’s the code:
$.getJSON('proxy.php?url=http://api.bukget.org/api/plugins', function(data){
var list = ['essentials', 'worldguard'];
//console.log(data);
$.each(data, function(i, plugin){
if (plugin === list) {
console.log('found!');
} else {
return false;
}
});
});
What am I missing from my code?
Using A Proxy:
<?php
if (!isset($_GET['url'])) die();
$url = urldecode($_GET['url']);
$url = 'http://' . str_replace('http://', '', $url); // Avoid accessing the file system
echo file_get_contents($url);
?>
Which makes the data (snippet):
["a5h73y", "ab-marriage", "abacus", "abag", "abandonedcarts", "abilitytrader", "abitofrealism", "aboot", "absorbchests", "acc", "acceptdarules", "acceptrules", "accesscontrol", "accessories", "accident-tnt", "accountlock", "achat", "achievement", "achievements", "acientcave", "acommands", "actionzones", "activator", "activityhistory", "activitypromotion", "activitytracker"]
return falsewill break out of the$.eachifplugin !== listin the first iteration.Edit: If you want to find for any of items inside
listand stop matching it’d be:Fiddle
If you want to find both of them:
Fiddle