interclubs
asked on
JavaScript function to check CSV against some JSON
So I am looking for a function that I can use like this:
checkPermission('email,sta tus_update ,publish_s tream,offl ine_access ');
function checkPermission(csvList) {
jsonList = '...';
}
So inside the function it would loop through some JSON (below) and compare each item in csvList to make sure it appears in the JSON. If each item in the csvList appears in the JSON it returns true, if not false...
JSON:
{"extended":["status_updat e","photo_ upload","v ideo_uploa d","offlin e_access", "email","c reate_note ","share_i tem","publ ish_stream ","contact _email","m anage_page s"],"user" :["read_st ream","pub lish_strea m","access _private_d ata"],"fri ends":["re ad_stream" ,"access_p rivate_dat a"]}
checkPermission('email,sta
function checkPermission(csvList) {
jsonList = '...';
}
So inside the function it would loop through some JSON (below) and compare each item in csvList to make sure it appears in the JSON. If each item in the csvList appears in the JSON it returns true, if not false...
JSON:
{"extended":["status_updat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
solved it
Thanks for the points!
extended -- an array of different permissions
user -- an array of different permissions
friends -- an array of different permissions
Now what you want to do is,
1) take each elements from csv
var allCSVItems = csvList.split(",");
2) loop through them
for ( var counter = 0; counter < allCSVItems.length; counter ++)
{
}
3) inside the loop you will check for all the csv items, if they are present in any of the arrays in JSON object
see how to check for an element in array
http://stackoverflow.com/questions/1181575/javascript-determine-whether-an-array-contains-a-value
http://stackoverflow.com/questions/237104/javascript-array-containsobj
4) if any of the csv element is not found return false, else return true in the end
let me know if more help is required