JavaScript How to remove certain element from Array
By:Roy.LiuLast updated:2019-08-11
In JavaScript, we can combine indexOf() and splice() to remove a certain element from an Array.
var array = [ 1 , 2 , 3 , 4 , 5 ]; console.log(array) // I want remove num 4, find the index first, -1 if it is not present. var index = array.indexOf( 4 ); if (index > - 1 ) { // found array.splice(index, 1 ); // array = [1, 2, 3, 5]; console.log(array); var lang = [ 'java' , 'node js' , 'javascript' , 'pyhton' ]; console.log(lang) // I want remove node js var index = lang.indexOf(`node js`); if (index > - 1 ) { lang.splice(index, 1 ); //lang = ['java', 'javascript', 'pyhton']; console.log(lang); |
From:一号门
Previous:log4j2.xml example
RELATED ARTICLES
- JS拖动选择 table 里的单元格
- javascript异步处理与Jquery的deferred对象总结
- javascript 内置对象 math,global
- javascript 基本包装类型
- javascript function 使用注意事项
- 用js实现网页滑屏解锁,类似iphone解锁功能(附源码下载)
- activex和javascript交互(delphi版本)
- 收藏的一个用JAVASCRIPT 操作 HTML Select 标签的东西
- 实现两个select同步
- 收集了很多JAVASCRIPT 事件
- Javascript处理选择很多CHECKBOX选项问题
- JAVASCRIPT中引号的处理
- How to execute JavaScript in Selenium WebDriver
- How to access JSON object in JavaScript
- MongoDB Remove a field from array
- MongoDB How to remove a field from document
- Java How to print an Array
- Java How to join Arrays
- Java How to convert Array to Stream
- How to copy an Array in Java
COMMENTS