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

前端 未结 16 2072
余生分开走
余生分开走 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 10:12

    Answer sans superfluous edge cases:

    const thingsWithoutNulls = things.reduce((acc, thing) => {
      if (thing !== null) {
        acc.push(thing);
      }
      return acc;
    }, [])
    

提交回复
热议问题