I am attempting to filter an array of JSON objects. I am new to JavaScript and trying to do it in coding languages that I used to. Basically, I want to take the following array of objects.
var result = [
{
date : '2016-11-21',
name: 'Bob',
score: 0.1034947
},
{
date : '2016-10-21',
name: 'Bill',
score: 0.2081911},
{
date : '2016-10-21',
name: 'Mary',
score: 0.234947
},
{
date : '2016-10-21',
name: 'Bob',
score: 0.1034947
},
{
date : '2016-11-21',
name: 'Bill',
score: 0.2081911},
{
date : '2016-11-21',
name: 'Mary',
score: 0.234947
},
{
date : '2016-12-21',
name: 'Bob',
score: 0.1034947
},
{
date : '2016-12-21',
name: 'Bill',
score: 0.2081911},
{
date : '2016-12-21',
name: 'Mary',
score: 0.234947
}
]
I then want to filter based on objects. So for example.
var selected_Names = ['Bob','Mary']
I want to return Bob and Mary's information only in this scenario.
[
{
date : '2016-11-21',
name: 'Bob',
score: 0.1034947
},
{
date : '2016-10-21',
name: 'Mary',
score: 0.234947
},
{
date : '2016-10-21',
name: 'Bob',
score: 0.1034947
},
{
date : '2016-11-21',
name: 'Mary',
score: 0.234947
},
{
date : '2016-12-21',
name: 'Bob',
score: 0.1034947
},
{
date : '2016-12-21',
name: 'Mary',
score: 0.234947
}
]
Thanks!