久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

javascript - js如何將匹配到的數組元素刪掉?

瀏覽:108日期:2023-08-31 17:30:00

問題描述

var arr = [ { ServiceID: ’go-storage-127.0.0.1-8080-9090’, ServiceName: ’storage’, }, { ServiceID: ’System-xxx-192.168.0.111-8000-8000’, ServiceName: ’xxx’, }, { ServiceID: ’System-xxx2-192.168.0.111-8000-8000’, ServiceName: ’xxx2’, }, { ServiceID: ’System-xxx3-192.168.0.111-8000-8000’, ServiceName: ’xxx3’, }, {ServiceID: ’System2-xxx3-192.168.0.111-8000-8000’,ServiceName: ’xxx3’, }, {ServiceID: ’test-xxx3-192.168.0.111-8000-8000’,ServiceName: ’xxx3’,}];

將arr數組中ServiceID以test或者System開頭的數組元素刪掉 用刪掉的方法總是沒法講匹配到的全刪,哪位高手能幫個忙呢?謝謝!

問題解答

回答1:

arr = arr.filter(item => !(/^test|^System/i.test(item.ServiceID)))

回答2:

var startsWithArr = strArr => str => { return strArr.some(e => str.startsWith(e)); }var starts = startsWithArr([ ’test’, ’System-’]);var filterArr = arr => { arr.filter(e => !starts(e.ServiceID)); }回答3:

用Array.filter方法,將過濾后的數組賦值回arr;

arr = arr.filter(function(item) { return !(/^(test|System)/g.test(item.ServiceId || ’’));});

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 涡阳县| 玉山县| 南京市| 岳普湖县| 义马市| 贡嘎县| 甘孜县| 蒙山县| 土默特左旗| 江永县| 巴林左旗| 锡林郭勒盟| 博客| 阳江市| 阿巴嘎旗| 云浮市| 洱源县| 威海市| 德江县| 调兵山市| 华亭县| 平湖市| 隆回县| 天水市| 盐山县| 广昌县| 济源市| 江永县| 都昌县| 通许县| 广德县| 陈巴尔虎旗| 龙泉市| 龙井市| 五峰| 子长县| 武鸣县| 文水县| 元阳县| 肥东县| 新平|