Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. var myObject = {
  2. name1: {
  3. title: 'Mr',
  4. options: ['A', 'B', 'C'],
  5.  
  6. },
  7. name2: {
  8. title: 'Mrs',
  9. options: ['C', 'D', 'E'],
  10.  
  11. }
  12. };
  13.  
  14. function myFunction(optionSearch) {
  15. console.log(optionSearch);
  16. for(var i in myObject) {
  17. if (myObject[i].options.indexOf(optionSearch) >= 0)
  18. console.log(i + ' is equal to optionSearch');
  19. else {
  20. console.log('No match');
  21. }
  22. }
  23. }
  24.  
  25. Object.keys(myObject)
  26. .filter((key) => {
  27. return myObject[key].options.includes(optionSearch)
  28. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement