How can I remove an array element with a substring?

  • 0
    Need to remove all elements containing substring, my attempt

    let hrefs = [
      '/upload/iblock/5f8/DKS-Prays_list-ot-01.11.20.xls',
      '/upload/iblock/2b8/dkc-_-kabelenesushchie-sistemy-i-eui-_2019-izdanie-34_.pdf',
      '/upload/iblock/004/dkc-_-resheniya-dlya-avtomatizatsii-i-it-_2019-izdanie-34_.pdf',
      '/upload/iblock/878/dkc-_-eui-avanti-_-2019.pdf',
      '/upload/iblock/fec/nizkovoltnoe-oborudovanie-dkc.pdf'
    ]
     hrefs = hrefs.filter(function(val) { return val.indexOf(".pdf") + 1 });

    Result:
    '/upload/iblock/2b8/dkc-_-kabelenesushchie-sistemy-i-eui-_2019-izdanie-34_.pdf',
    '/upload/iblock/004/dkc-_-resheniya-dlya-avtomatizatsii-i-it-_2019-izdanie-34_.pdf',
    '/upload/iblock/878/dkc-_-eui-avanti-_-2019.pdf',
    '/upload/iblock/fec/nizkovoltnoe-oborudovanie-dkc.pdf

    Waiting:
    '/upload/iblock/5f8/DKS-Prays_list-ot-01.11.20.xls',
    JavaScript Anonymous, Mar 14, 2020

  • 2 Answers
  • 0
    hrefs.filter (n = & gt;! / \. pdf $ /. test (n))



    or



    hrefs.filter (n = & gt;! n.endsWith ('. pdf'))
    Lucy Anthony

  • 0
    hrefs.filter(function(val) { return val.indexOf(".pdf") === -1 });
    Evelyn McGee

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!