JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2564
  • Score
    100M100P100Q115329F
  • License MIT

Join arrays by common key or with custom matching function.

Package Exports

  • array-join

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (array-join) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

array-join

Join arrays by common key or with custom matching function.

build status

join(array1, array2, options)

with common key:

const { join } = require('array-join');

join([
    { id: 1, name: 'apple' },
    { id: 2, name: 'banana' },
    { id: 3, name: 'orange' }
  ],
  [
    { id: 1, color: 'red' },
    { id: 2, color: 'yellow' }
    { id: 4, color: 'blue' }
  ],
  { key: 'id' });

// result:
[
  { id: 1, name: 'apple', color: 'red' },
  { id: 2, name: 'banana', color: 'yellow' }
]

with different matching keys:

join([
    { id: 1, name: 'apple' },
    { id: 2, name: 'banana' },
    { id: 3, name: 'orange' }
  ],
  [
    { num: 1, color: 'red' },
    { num: 2, color: 'yellow' }
    { num: 4, color: 'blue' }
  ],
  { key1: 'id', key2: 'num' });

// result:
[
  { id: 1, name: 'apple', color: 'red' },
  { id: 2, name: 'banana', color: 'yellow' }
]

with custom matching function:

join([
    { a: 10, b: 2 },
    { a: 100, b: 3 },
    { a: 1000, b: 4 }
  ],
  [
    { p: 20, text: 'wow' },
    { p: 4000, text: 'cool' }
  ],
  { match: (x, y) => x.a * x.b === y.p });

// result:
[
  { a: 10, b: 2, p: 20, text: 'wow' },
  { a: 1000, b: 4, p: 4000, text: 'cool' }
]