JavaScript数组删除指定元素
^_^
function arrayRemoveItem(arr, delVal) {
if (arr instanceof Array) {
var index = arr.indexOf(delVal);
if (index > -1) {
arr.splice(index, 1);
}
}
}
Demo
// 在浏览器Console执行Demo
>function arrayRemoveItem(arr, delVal) {
> if (arr instanceof Array) {
> var index = arr.indexOf(delVal);
> if (index > -1) {
> arr.splice(index, 1);
> }
> }
>}
>var arr = ["a", "b", "c", "d", "e", "f", "g"];
>arr
<(7) ["a", "b", "c", "d", "e", "f", "g"]
>arrayRemoveItem(arr, 'd');
>arr
<(6) ["a", "b", "c", "e", "f", "g"]
:)
JavaScript数组删除指定元素的更多相关文章
- jquery数组删除指定元素的方法:grep()
jquery数组删除指定元素的方法:grep() 金刚 数组 jquery javascript 元素 遇到的问题 今天遇到一个问题,删除数组中的一个指定元素,并返回新的数组. 我定义的js数组是这样 ...
- JavaScript数组删除重复元素(去重)的方法
1. var arr=str.split(""); ;arr.length->i;i++){ ;j<arr.length;j++){ if(arr[j]==arr[i] ...
- js 数组删除指定元素
Array.prototype.remove = function(obj) { for (var i = 0; i < this.length; i++) { var temp = this[ ...
- js 删除数组的指定元素
//为数组对象增加相应的的方法,直接调用数组的removeByValue方法即可删除指定元素 Array.prototype.removeByValue = function (val) { for ...
- ES6数组中删除指定元素
知识点: ES6从数组中删除指定元素 findIndex()方法返回数组中满足提供的测试函数的第一个元素的索引.否则返回-1. arr.splice(arr.findIndex(item => ...
- List 循环删除 指定元素的 方法
使用Iterator进行循环,在删除指定元素.如果使用for 或 foreach 在删除指定下标是,list.size 会相应的缩短且下标前移,导致相邻满足条件的元素未删除 Iterator<S ...
- 【LeetCode每天一题】Find First and Last Position of Element in Sorted Array(找到排序数组中指定元素的开始和结束下标)
Given an array of integers nums sorted in ascending order, find the starting and ending position of ...
- java集合遍历删除指定元素异常分析总结
在使用集合的过程中,我们经常会有遍历集合元素,删除指定的元素的需求,而对于这种需求我们往往使用会犯些小错误,导致程序抛异常或者与预期结果不对,本人很早之前就遇到过这个坑,当时没注意总结,结果前段时间又 ...
- 详解JavaScript数组过滤相同元素的5种方法
详解JavaScript数组过滤相同元素的5种方法:https://www.jb51.net/article/114490.htm
随机推荐
- 潭州课堂25班:Ph201805201 django 项目 第三十六课 后台文章管理(课堂笔记)
get 请求, 1,获取文章标签 , 2,拿到前台传来的值, 3,根据前台传来的值在数据库中查询 4.,返回数据到前台,渲染, 分页算法 : 在 utils 下创建 paginator_script ...
- Vue常用模块
1.npm install Vue-Awesome-Swiper@v2.6.7 --save 实现轮播图 2.npm install axios 发送请求get,post
- 工程管理之makefile与自动创建makefile文件过程
(风雪之隅 http://www.laruence.com/2009/11/18/1154.html) Linux Makefile自动编译和链接使用的环境 想知道到Linux Makefile系统的 ...
- yii2 配合bootstrap添加按钮
新增一个按钮 1.bootstrap 官网:http://getbootstrap.com/ 2.bootstrap 中文官网:http://v3.bootcss.com/ 在视图文件中: <? ...
- NodeJS 连接接MySQL
NodeJS 连接接MySQL MySQL是常用数据库,作为后端模块,nodejs可以提供了mysql接口 安装 $ npm install mysql 测试代码 var mysql = requir ...
- keepalived+mysql backup服务器可ping通过vip但telnet vip+3306失败问题
环境: OS:CentOS 7_X64 数据库:mysql-5.7 MASTER:192.168.119.23 BACKUP:192.168.119.24 VIP:192.168.119.138 ke ...
- 词向量保存为txt
model.wv.save_word2vec_format('w2v_mod.txt',binary=False)
- ES6_入门(4)_数组的解构赋值
//2017/7/14 //变量的解构赋值(解构:Destructuring) //(1)数组的解构赋值 let [a,b,c]=[1,2,3];//模式匹配,只要等号两边的模式相同,左边的变量就会被 ...
- android: 在APP中显示高德地图SDK
一.搭建环境 参考资料:http://lbs.amap.com/api/android-sdk/guide/create-project/android-studio-create-project ...
- Project with Match in aggregate not working in mongodb
[问题] 2down votefavorite I am trying to fetch data based on some match condition. First I've tried th ...