1

Is there an easy way to loop through an object and find all strings with something like

 var types = [ ".jpg" , ".png" , ".mp3 ", ".mp4"];

The Object contains lots of sub-objects that may or may not have media files in them .

I just want a list of all media files in there?

beek
  • 3,522
  • 8
  • 33
  • 86

1 Answers1

0

Check here:

you can iterate over all object properties with this snippet:

for (var property in object) {
    if (object.hasOwnProperty(property)) {
       // iterate here over all types
       // like this:

       var filtered = types.filter(function(type){
                          return property.indexOf(type) > -1 ; // substr 
                     });

       if(filtered.length > -1){
       // found a type

       }
    }
}
Community
  • 1
  • 1
Ygalbel
  • 5,214
  • 1
  • 24
  • 32