How to remove an element from an array in JavaScript?

Instruction with code examples about popular JavaScript issue
09 August 2017   1053

Here is a to-do plan in order to remove an element from an array in JavaScript.

1. find the index of the element you want to remove:

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

Note: browser support for indexOf is limited; it is not supported in Internet Explorer 7 and 8.

2. remove it with splice:

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

The second parameter of splice is the number of elements to remove. Note that splicemodifies the array in place and returns a new array containing the elements that have been removed.

If you need indexOf in an unsupported browser, try the following polyfill.

Array.prototype.indexOf || (Array.prototype.indexOf = function(d, e) {
    var a;
    if (null == this) throw new TypeError('"this" is null or not defined');
    var c = Object(this),
        b = c.length >>> 0;
    if (0 === b) return -1;
    a = +e || 0;
    Infinity === Math.abs(a) && (a = 0);
    if (a >= b) return -1;
    for (a = Math.max(0 <= a ? a : b - Math.abs(a), 0); a < b;) {
        if (a in c && c[a] === d) return a;
        a++
    }
    return -1
});

 

What's new in IntelliJ IDEA 2018.2?

New version of popular IDE improved Spring and Spring Boot support
18 July 2018   110

The new version of IDE IntelliJ IDEA from JetBrains under the number 2018.2 has introduced several functions for developers using Spring and Spring Boot frameworks. Among the innovations: support for Spring Integration, runtime diagrams, library bin management and many minor fixes and improvements.

New features of IntelliJ IDEA

Now you can visualize the components in the system using the new Spring Integration diagram. All versions above 5.0 are supported.

Spring Integratio Diagram
Spring Integration Diagram

It shows all the gateways, channels and bridges of the application, regardless of whether they are configured using Java or XML annotations.

The IDE also received code completion and navigation for such integration annotations as @BridgeTo/From and @EnablePublisher:

Integration Annotations
Integration Annotations

In the new version of IntelliJ IDEA, you can view the dependencies during the execution of the Spring Boot application as a diagram through the control panel. To do this, go to the "Endpoints" section and enable the "Diagram Mode" function:

Runtime Dependencies
Runtime Dependencies

If there are too many beans in the project, the non-user codes can be disabled using the new "Show / Hide Library Beans" switch:

Show / Hide library beans
Show / Hide library beans

In addition, in 2018.2, you can start, modify, and test the display of HTTP requests in the "Endpoints" tab:

HTTP request
HTTP request

A complete list of improvements and changes is available in the technical update document. According to the developers, a lot of work has been done to improve performance in large projects.