splice

Vue中splice的使用

匿名 (未验证) 提交于 2019-12-03 00:20:01
splice(index,len,[item])它也可以用来替换/删除/添加数组内某一个或者几个值(该方法会改变原始数组) item:替换的值,删除操作的话 item为空 删除 : //删除起始下标为1,长度为1的一个值(len设置1,如果为0,则数组不变) var arr = ['a','b','c','d']; arr.splice(1,1); //删除起始下标为1,长度为2的一个值(len设置2) var arr2 = ['a','b','c','d'] arr2.splice(1,2); //['a','d'] 替换: //替换起始下标为1,长度为1的一个值为‘ttt’,len设置的1 var arr = ['a','b','c','d']; arr.splice(1,1,'ttt'); //替换起始下标为1,长度为2的两个值为‘ttt’,len设置的1 var arr2 = ['a','b','c','d']; arr2.splice(1,2,'ttt'); 添加: //在下标为1处添加一项'ttt' var arr = ['a','b','c','d']; arr.splice(1,0,'ttt'); 文章来源: Vue中splice的使用

vant checkBox 批量删除

匿名 (未验证) 提交于 2019-12-03 00:08:02
有两种实现方式,当然不止两种 一:使用 filter 将我们需要的过滤出来,也就是哪个没有选中就过滤哪个 二:使用splice数组方法,将我们选择需要删除的 index 放到一个数组里面,然后进行删除。 splice有一个坑(splice会改变原数组) 先说说方法一: /* 假设我们是依赖这个数据来进行渲染,v-for="(item,index) in addressList" 使用filter 的话我们可以给每一个对象添加一个key值isDel ,你在增加的一个人时也只需要push {"name": "", "gender": "", "age":"", "isDel":false}         给每一个对象加入key为isDel:false      addressList.forEach((item,index)=>{        item["isDel"] = false      })     配合使用vantUI 里面的 <van-checkbox v-model="item.isDel"></van-checkbox> 只要当复选框被选中时 isDel 就会改为 true         最后写上 addressList = addressList.filter(item=>item.isDel === false) 这就将没选中的过滤出来

区分slice,splice和split方法

匿名 (未验证) 提交于 2019-12-02 23:45:01
1.slice(数组) 用法:array.slice(start,end) 解释:该方法是对数组进行部分截取,并返回一个数组副本;参数start是截取的开始数组索引,end参数等于你要取的最后一个字符的位置值加上1(可选) 2.slice(字符串) 用法:string.slice(start,end) 解释:slice方法复制string的一部分来构造一个新的字符串,用法与参数匀和数组的slice方法一样;end参数等于你要取的最后一个字符的位置值加上1 3.splice(数组) 用法:array.splice(start,deleteCount,item...) 解释:splice方法从array中移除一个或多个数组,并用新的item替换它们。参数start是从数组array中移除元素的开始位置。参数deleteCount是要移除的元素的个数。 如果有额外的参数,那么item会插入到被移除元素的位置上。它返回一个包含被移除元素的数组。 4.split(字符串) 用法:string.split(separator,limit) 解释:split方法把这个string分割成片段来创建一个字符串数组。可选参数limit可以限制被分割的片段数量。separator参数可以是一个字符串或一个正则表达式。如果 separator是一个空字符,会返回一个单字符的数组。

前端实习面试题整理(三)【快排、数组对象】

非 Y 不嫁゛ 提交于 2019-12-02 23:40:34
(以下是从各种网站、同学处整理的前端实习面试题,答案也为自己整理,有错误的话欢迎指正) 3、 手写快排(顺带看了冒泡)   ①快排   话不多说,直接上代码: function quickSort(arr) { if (arr.length <= 1) { return arr; } var index = Math.floor(arr.length / 2); var pivot = arr.splice(index, 1)[0]; var left = [], right = []; for (var m = 0; m < arr.length; m++) { if (arr[m] < pivot) { left.push(arr[m]); } else { right.push(arr[m]); } } return quickSort(left).concat([pivot], quickSort(right)); }   快排的思想:从数组中选定一个基数,然后把数组中的每一项与此基数做比较,小的放入一个新数组,大的放入另外一个新数组。然后再采用这样的方法操作新数组。直到所有子集只剩下一个元素,排序完成。通过index选出的pivot即为基数(一般选用数组中间的数),然后本文后续会介绍JS的数组Array中splice()和concat()的用法。   【时间复杂度

javascript splice skipping element- why this behaviour

只愿长相守 提交于 2019-12-02 22:57:43
问题 I was working with splice within a nested for loop and I came across a behaviour I could not understand. var a = [0, 1, 2, 3, 4]; for (b in a) { console.log(a); for (c in a) { console.log(c + '==' + a[c]); if (c === "1") a.splice(c, 1); } } console.log(a); Its output is strange [0, 1, 2, 3, 4] "0==0" "1==1" "2==3" // why is index 2 referring to value 3 , whereas it should refer to 2 "3==4" [0, 2, 3, 4] "0==0" "1==2" "2==4" // index 2 referring to value 4 , whereas it should refer to 3 [0, 3,

Linux Zero-Copy: Transfer memory pages between two processes with vmsplice

独自空忆成欢 提交于 2019-12-02 22:25:57
Currently, I am trying to understand the value of splice/vmsplice. Regarding the use case of IPC, I stumbled upon the following answer on stackoverflow: https://stackoverflow.com/a/1350550/1305501 Question: How to transfer memory pages from one process to another process using vmsplice without copying data (i.e. zero-copy)? The answer mentioned above claims that it is possible. However, it doesn't contain any source code. If I understand the documentation of vmsplice correctly, the following function will transfer the memory pages into a pipe (kernel buffer) without copying, if the memory is

javascript splice skipping element- why this behaviour

依然范特西╮ 提交于 2019-12-02 13:05:27
I was working with splice within a nested for loop and I came across a behaviour I could not understand. var a = [0, 1, 2, 3, 4]; for (b in a) { console.log(a); for (c in a) { console.log(c + '==' + a[c]); if (c === "1") a.splice(c, 1); } } console.log(a); Its output is strange [0, 1, 2, 3, 4] "0==0" "1==1" "2==3" // why is index 2 referring to value 3 , whereas it should refer to 2 "3==4" [0, 2, 3, 4] "0==0" "1==2" "2==4" // index 2 referring to value 4 , whereas it should refer to 3 [0, 3, 4] "0==0" "1==3" [0, 4] I am splicing index 1 and it is skipping the next element . Why this Behaviour

Python - regex - Splitting string before word

岁酱吖の 提交于 2019-12-02 06:27:59
问题 I am trying to split a string in python before a specific word. For example, I would like to split the following string before "path:" . split string before "path:" input: "path:bte00250 Alanine, aspartate and glutamate metabolism path:bte00330 Arginine and proline metabolism" output: ['path:bte00250 Alanine, aspartate and glutamate metabolism', 'path:bte00330 Arginine and proline metabolism'] I have tried rx = re.compile("(:?[^:]+)") rx.findall(line) This does not split the string anywhere.

删除数组指定元素

与世无争的帅哥 提交于 2019-12-02 02:36:37
使用.splice方法 splice(index ,num) index表示下标位置 num表示删除数量 findIndex表示找到某元素的下标位置 this.imgList.splice(this.imgList.findIndex(item => item.url === path), 1) 来源: https://www.cnblogs.com/zzz-knight/p/11726291.html