N
N
NO2014-08-29 09:52:37
opencart
NO, 2014-08-29 09:52:37

How to get elements from an array that contain def. characters?

There are arrays like:

[ "Hawaii mvc_mcycle_Data-Summary0812a.html", "bg1.png", "compatibility.js", "f1.woff", "f2.woff", "f3.woff", "f4.woff", "f5.woff", "pdf2htmlEX-64x64.png", "pdf2htmlEX.min.js" ]

From them, I need to get the elements that contain the last characters: (.png, .jpg, .jpeg, .gif, .html, .htm, .css). But at the same time, ignore the element with the content "pdf2htmlEX-64x64.png"

I couldn't even start:
function infoJSON(myURL) {
  $.ajax({
    url: myURL,
    dataType: "text",
    success: function(data) {
      var v = $.parseJSON(data);
      var arrayFiles = v.output.files;
      
      var png = $(arrayFiles':not([.png$])').splice();
      
      $(".class").html(png);
    }
  });
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel, 2016-07-22
@Palych_tw

Everything is allowed. But you have to do it manually. In opencart, a lot of scripts are written in the middle of the desired template (module or page), for example, all sorts of sliders, lightboxes, etc. And they will stop working if you transfer the library necessary for them, owl carousel or jQuery in general, from the header to the footer. If you are doing all this to please google page speed insight, I would not advise doing this. Win a couple of points and break the site.. it's not worth it

S
Sergey, 2014-08-29
@Mihail9575

function filterFiles(arr, extensions, ignore) {
    extensions = extensions || [];
    ignore = ignore || [];
    
    var getFileExt = function (filename) {
        return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename)[0] : undefined;
    }
    
    return arr.filter(function (item) {
        return -1 === ignore.indexOf(item) && -1 !== extensions.indexOf(getFileExt(item));
    });
}

// usage
var files = filterFiles([ "Hawaii mvc_mcycle_Data-Summary0812a.html", "bg1.png", "compatibility.js", "f1.woff", "f2.woff", "f3.woff", "f4.woff", "f5.woff", "pdf2htmlEX-64x64.png", "pdf2htmlEX.min.js" ], ['png'], ['pdf2htmlEX-64x64.png']);

Y
yernende, 2014-08-29
@yernende

Look in the error console.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question