ToArray

Converts objects into meaningful sequences.

Github repository for your stars.

Usage

Install

$ npm install json-function

Import

import { toArray } from 'json-function';

Usage

Example Data

const data = {
  'SpahhfW88GEcnVEXBkSB': {
    name: 'John'
  },
  'kDdjXxZWZwzKfYOyLUkE': {
    name: 'Mike'
  },
  'yPND1ItYbQXgoBXIAsz8': {
    name: 'Dan'
  }
};

Default key

toArray(data);

Output

[
  {
    uid: 'SpahhfW88GEcnVEXBkSB',
    name: 'John'
  },
  {
    uid: 'kDdjXxZWZwzKfYOyLUkE',
    name: 'Mike'
  },
  {
    uid:  'yPND1ItYbQXgoBXIAsz8',
    name: 'Dan'
  }
];

Use custom key

toArray(data, { key: '_id_' });

Output

[
  {
    _id_: 'SpahhfW88GEcnVEXBkSB',
    name: 'John'
  },
  {
    _id_: 'kDdjXxZWZwzKfYOyLUkE',
    name: 'Mike'
  },
  {
    _id_:  'yPND1ItYbQXgoBXIAsz8',
    name: 'Dan'
  }
];

Last updated