Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. var obj = {
  2. online_rate_1: "$5.00",
  3. online_rate_2: "$22.00",
  4. online_rate_3: "$44.00",
  5. rate_1: "$9.00",
  6. rate_2: "$18.00",
  7. rate_3: "$30.00",
  8. rate_description: "<p>Some description text</p>",
  9. time_period_1: "0 - 0.5 Hours",
  10. time_period_2: "0.5 - 1 Hours",
  11. time_period_3: "1 - 2 Hours",
  12. }
  13.  
  14. function findKeysWithPrefix(object, prefix) {
  15. var arr = [];
  16. for ( var property in object) {
  17. if (
  18. object.hasOwnProperty(property)
  19. && property.toString().startsWith(prefix)
  20. && /\d/.test(property.toString())
  21. ) {
  22. arr.push(object[property]);
  23. }
  24. }
  25. return arr;
  26. }
  27.  
  28. console.log( findKeysWithPrefix( obj, 'online' ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement