Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var myObject = {
- name1: {
- title: 'Mr',
- options: ['A', 'B', 'C'],
- },
- name2: {
- title: 'Mrs',
- options: ['C', 'D', 'E'],
- }
- };
- function myFunction(optionSearch) {
- console.log(optionSearch);
- for(var i in myObject) {
- if (myObject[i].options.indexOf(optionSearch) >= 0)
- console.log(i + ' is equal to optionSearch');
- else {
- console.log('No match');
- }
- }
- }
- Object.keys(myObject)
- .filter((key) => {
- return myObject[key].options.includes(optionSearch)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement