array-compactto

Remove falsy values from array, like _.compact().

Usage no npm install needed!

<script type="module">
  import arrayCompactto from 'https://cdn.skypack.dev/array-compactto';
</script>

README

array-compactto

NOTE: array-compactto was renamed to @extra-array/compact. NPM

Remove falsy values from array, like _.compact().

const compactTo = require('array-compactto');
// compactTo(<array>, [begin=0], [end], [target=[]], [at])

var a = ['y', null, 'o', null, 'l', null, 'o'];
compactTo(a);
// ['y', 'o', 'l', 'o']
compactTo(a, 1);
// ['o', 'l', 'o']
compactTo(a, 1, 6);
// ['o', 'l']
compactTo(a, 1, 6, ['f', 'o']);
// ['f', 'o', 'o', 'l']
compactTo(a, 1, 6, ['f', 'o'], 1);
// ['f', 'o', 'l']