首先需要找到元素的下标:

var array = [2, 5, 9];
var index = array.indexOf(5);

使用splice函数进行移除:

if (index > -1) {
array.splice(index, 1);
}

splice函数的第二个参数指删除的数目。splice直接修改原数组,并把删除的所有元素以另一个新数组的方式返回。

js移除Array中指定元素的更多相关文章

  1. LeetCode 27 Remove Element (移除数组中指定元素)

    题目链接: https://leetcode.com/problems/remove-element/?tab=Description   Problem : 移除数组中给定target的元素,返回剩 ...

  2. 【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 ...

  3. js能力测评——移除数组中的元素

    移除数组中的元素 题目描述 : 移除数组 arr 中的所有值与 item 相等的元素.不要直接修改数组 arr,结果返回新的数组 示例1 输入 [1, 2, 3, 4, 2], 2 输出 [1, 3, ...

  4. 使用HTML5的JS选择器操作页面中的元素

    文件命名为:querySelector.html,可在Chrome浏览器中预览效果. 1 <!DOCTYPE html> 2 <html lang="en"> ...

  5. 移除数组中指定键(Yii2)

    /** * 移除数组中指定key * @param $data * @param $key * @return array */ public static function removeKey($d ...

  6. Js/Jquery获取iframe中的元素

    转载: Js/Jquery获取iframe中的元素 - - ITeye技术网站http://java-my-life.iteye.com/blog/1275205 在web开发中,经常会用到ifram ...

  7. 巧妙利用ToArray()函数移除集合中的元素

    当我们对集合foreach遍历时,不能直接移除遍历的集合的元素,解决的方法有很多种,见我之前的随笔: http://www.cnblogs.com/527289276qq/p/4331000.html ...

  8. LeetCode数组移除数组中目标元素等题目

    一种自己解题,一种高赞解题 /** * 移除数组中目标元素,返回新数组长度 * @param nums * @param val * @return */ public int removeEleme ...

  9. 三种移除list中的元素(可靠)

    /** * 直接使用foreach方法移除list中的元素会抛异常 * Exception in thread "main" java.util.ConcurrentModific ...

随机推荐

  1. Logback配置解析

    logback优点 比较吸引的几个优点如下: 内核重写,初始化内存加载更小 文档比较齐全 支持自动重新加载配置文件,扫描过程快且安全,它并不需要另外创建一个扫描线程 支持自动去除旧的日志文件,可以控制 ...

  2. JAVA 9 新特性

     Oracle已将JAVA 9的开发提上日程.OpenJDK上已经出现了关于下一个主版本JAVA 9的改进建议(JEP).与以往不同,Oracle在这次谈及了一些真正的特性.而早期对于JDK9的声明仅 ...

  3. [leetcode DP]63. Unique Paths II

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  4. C# String.Format 格式化字符串 数字/时间

    首先献给只想知道结果的人 格式化 DateTime 对象 标准 数字 格式化 Int Decimal Float Double 关于这一块一直不是很清楚,MSDN 上也不够清晰. 就花了点时间敲了一下 ...

  5. [BZOJ5306][HAOI2018]染色(容斥+FFT)

    https://www.cnblogs.com/zhoushuyu/p/9138251.html 注意如果一开始F(i)中内层式子中j枚举的是除前i种颜色之外还有几种出现S次的颜色,那么后面式子就会难 ...

  6. hdu 1518 dfs+剪枝

    题目大意:几根棒子能否组成一个正方形 Sample Input3           //测试组数4 1 1 1 1   //棒子数目以及每根棒子的长度5 10 20 30 40 508 1 7 2 ...

  7. 【BZOJ】4720: [Noip2016]换教室

    4720: [Noip2016]换教室 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1690  Solved: 979[Submit][Status ...

  8. 【bzoj2005】 [Noi2010]能量采集 数学结论(gcd)

    [bzoj2005] [Noi2010]能量采集 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnli ...

  9. WhatsApp & Tasker for Android – Read & Write messages

    WhatsApp & Tasker for Android – Read & Write messages The requirement for the automation is ...

  10. Namespace declaration statement has to be the very first statement in the script

    php 中 Namespace declaration statement has to be the very first statement in the script 错误解决方法: 在PHP文 ...