I need solution not using any frameworks, just plain javascript.
I have initial values that I need to search in array items:
var name = 'blah';
var click = 'double';
I have array like this:
var items =
[
{
name: 'blah',
click: 'single',
url: 'url1',
token: 'token1'
},
{
name: 'blah',
click: 'double',
url: 'url2',
token: 'token2'
},
{
name: 'bar',
click: 'double',
url: 'url3',
token: 'token3',
},
{
name: 'baz',
click: 'single',
url: 'url4',
token: 'token4'
}
];
When I find the object that contains both values, in this case:
{
name: 'blah',
click: 'double',
url: 'url2',
token: 'token2'
}
Than, I need to assign rest of values from that object to separate variables. In this case result should be:
var url = 'url2';
var token = 'token2'
The problem is that i don't know what the search values will be each time. For example on each button press, search values will be different. Different value for "name" and different value for "click".
I just want to check if it is the same across all objects in that array and assign rest of values to variables.
UPDATE:
I was thinking maybe to first create array of found objects that contain matched value from "var name = blah"
var names = items.filter(function(item) {return item.name === 'blah'});
and then search over "names" array to find what is matching to var click = "double".
var match = names.filter(function(matchitem) {return matchitem.click === "double"});