How to skip over an element in .map()?

前端 未结 16 2027
余生分开走
余生分开走 2020-11-27 09:26

How can I skip an array element in .map?

My code:

var sources = images.map(function (img) {
    if(img.src.split(\'.\').pop() === \"json         


        
16条回答
  •  再見小時候
    2020-11-27 09:52

    You can do this

    var sources = [];
    images.map(function (img) {
        if(img.src.split('.').pop() !== "json"){ // if extension is not .json
            sources.push(img.src); // just push valid value
        }
    });

提交回复
热议问题