I've got a serialized JSON collection:
[
{
"_id":"person1",
"date":"7/20/2014 17:20:09",
"listed_name":"Tom",
"name":"Tom",
"contact_info":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e0a11133e19131f1712501d1113">[email protected]</a>"
},
{
"_id":"person2",
"date":"7/20/2014 17:20:09",
"listed_name":"Jane",
"name":"Jane",
"contact_info":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8bdbeef9f8e4e5b9cbece6eae2e7a5e8e4e6">[email protected]</a>"
},
{
"_id":"person3",
"date":"7/20/2014 17:20:09",
"listed_name":"John",
"name":"John",
"contact_info":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="14447166677b7a27547379757d783a777b79">[email protected]</a>"
}
]
On another page, there is property name information...
["_id", "date", "listed_name"]
The question at hand is...
Using JavaScript, how can I filter the JSON objects to only display columns specified in the second array?
For example: if using this array ["_id"]
... how might one use it as a filter to show only the _id
data but exclude date
, listed_name
, name
, etc... for all objects?
When filtering with ["_id"]
array, the expected console output should be as follows:
person1
person2
person3