How to empty an array in JavaScript?

Four methods on how to empty an array in JavaScript with code examples
27 September 2017   1038

We've made a research and found out 4 different methods that will help you to empty an array in JavaScript.

As example, we will use array A = [1,2,3,4]; 

Method 1

A = [];

This code will set the variable A to a new empty array. This is perfect if you don't have references to the original array A anywhere else because this actually creates a brand new (empty) array. You should be careful with this method because if you have referenced this array from another variable or property, the original array will remain unchanged.

Method 2

A.length = 0

This will clear the existing array by setting its length to 0. It also works when using "strict mode" in ECMAScript 5 because the length property of an array is a read/write property.

Method 3

A.splice(0,A.length)

Using .splice() will work perfectly, but since the .splice() function will return an array with all the removed items, it will actually return a copy of the original array. Benchmarks suggest that this has no effect on performance whatsoever.

Method 4 

while(A.length > 0) {
    A.pop();
}

 

What is Vim.Wasm?

Small introduction to Vim port to WebAssembly with screenshot and developer notes
16 July 2018   90

Vim.wasm is experimental fork of Vim editor to compile it into WebAssembly using emscripten and binaryen.

Developer added some notices:

  • Please access from a desktop browser (Chrome/Firefox/Safari/Edge). Safari seems the best on macOS.
  • Please avoid mobile networks. Your browser will fetch some large files (up to 2.5MB).
  • vim.wasm takes key inputs from DOM keydown event. Please disable your browser extensions which affect key inputs (incognito mode would be the best).
  • This project is very early phase of experiment. Currently only tiny features are supported. More features will be implemented (please see TODO section). And you may notice soon on trying it... it's buggy :)
  • If inputting something does not change anything, please try to click somewhere in the page. Vim may have lost the focus.

The goal of this project is running Vim editor on browser by compiling Vim C sources into WebAssembly. 

Vim.wasm screenshot
Vim.wasm screenshot 

WebAssembly frontend for Vim is implemented as a new GUI frontend. C sources are compiled to each LLVM bitcode files and then they are linked to one bitcode file vim.bc by emccemcc finally compiles the vim.bc into vim.wasm binary using binaryen and generates HTML/JavaScript runtime.

You can find more info at GitHub.