1.0.1 • Published 5 years ago

array-flat-polyfill v1.0.1

Weekly downloads
196,252
License
CC0-1.0
Repository
github
Last release
5 years ago

Array Flat Polyfill

NPM Version Build Status Support Chat

Array Flat Polyfill is a polyfill for Array.prototype.flat and Array.prototype.flatMap, following the TC39 Proposal.

npm install array-flat-polyfill --save

The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

[1, 2, [3, 4, [5, 6]]].flat(2) // [1, 2, 3, 4, 5, 6]

The flatMap() method maps each element using a mapping function, then flattens the result into a new array.

[1, 2, 3, 4].flatMap(x => [x * 2]); // [2, 4, 6, 8]

The script is 261 bytes when minified and gzipped. It works in all browsers, going as far back as Internet Explorer 9.

Usage

For immediate usage, add this script to your document:

<script src="https://unpkg.com/array-flat-polyfill"></script>

For Node usage, add Array Flat Polyfill to your project:

npm install array-flat-polyfill

Include Array Flat Polyfill in your JS:

import 'array-flat-polyfill';
quintype-aceairsiders-mapping-toolvite-plugin-broswer-extensionvsdxjs@everything-registry/sub-chunk-1164supercharged-rte-serializerglob-import-loaderjolt-frameworkjs-kmb-apihc-mid-csphc-mid-ip-filterhexmaphowdygo-rollup-plugin-chrome-extensionmamba-gameimhotapffmpeg-ffabreactorfast-tagexpress-routes-filefastify-minifyftl-netlify-buildgatsby-source-directus-cmsgatsby-theme-styled-mdxgenerator-gatsbyosm-edit-bundle@dchicchon/vite-plugin-chrome-extension@lodgify/uinode-pandoc-filternpm-pack-here@monstrs/build-images-last-changed@kqinfo/uiplayground-landscape@parisholley/vega-lite@hydrosquall/vega-liteprasadacm@robodo/dottlequrtty-js-sdkquestmark@quasibit/eleventy-plugin-sitemap@shepherdorg/deployer@shepherdorg/logger@shiftcommerce/shift-next@skycell-ag/richtable@zoovu/runner-browser-api@zalastax/nolb-array-@statsforvalteren/stafschemaeditor@vimlet/eon-cli@sparanoid/bilibili-live-ws@ucd-lib/cork-app-buildrelay-store-types-generator@web/test-runner-junit-reporter@warungpintar/warlock@ably/uirollup-plugin-chrome-extension@authorx/compilerbrighterscriptcantaracantara-phcanopy-js@dogger/cli@crds_npm/crds-componentssvelte-router-simplesvelte-router-simple-2bilibili-live-wsbilibili-live-ws-vue3bv-vite-crx@dexus1985/eleventy-plugin-sitemapcatenatzo-analyzetopolacoveradgeaslint@brightspace-ui-labs/ou-filtertransform-json-api@contentstack/json-rte-serializerarena-transform-new@berhalak/jssoc-frontendblitter@codingfly/remax-designw-projectwmn-design-systemcustom-api-onfido-sdk-uits-comment-predictorvite-plugin-chrome-extensionvite-plugin-chrome-extension-updatedvite-plugin-wave-extension@essentialaccessibility/aslint@dxdeveloperexperience/git-webhooks@dxdeveloperexperience/hygie@fraserdarwent/svelte-router@gedhean/rollup-plugin-chrome-extension@infinitebrahmanuniverse/nolb-array-
1.0.1

5 years ago

1.0.0

5 years ago