How to remove an element from an array in JavaScript?

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

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;
    return -1


Supra Smart Cloud TV to be Hacked

Now hacker can replace video being watched with own content
04 June 2019   301

A vulnerability has been identified on the Supra Smart Cloud TV (CVE-2019-12477). It makes possible to replace the transmission currently being watched for the content of the attacker. As an example, the output of a bogus emergency warning is shown.

To attack, just send a specially designed network request that does not require authentication. In particular, hacker can contact the handler "/ remote / media_control? Action = setUri & uri =" by specifying the URL of the m3u8 file with the video parameters, for example " .com / fake_broadcast_message.m3u8 ".

In most cases, access to the IP address of the TV is limited to the internal network, but since the request is sent via HTTP, it is possible to use methods to access internal resources when the user opens a specially designed external page (for example, under the request of a picture or using the DNS rebinding method).