JavaScript How to remove certain element from Array
摘要: In JavaScript, we can combine indexOf() and splice() to remove a certain element from an Array.
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);
上一篇:
log4j2.xml example
下一篇: Log4j 2 java.lang.NoClassDefFoundError: com/lmax/disruptor/EventTranslatorVararg
下一篇: Log4j 2 java.lang.NoClassDefFoundError: com/lmax/disruptor/EventTranslatorVararg