0.0.4 • Published 5 years ago

realjay-array-group v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

realjay-array-group

This is a vue plugin created to help group array objects by specified key. Most times we recieve a server response with array of objects and we need to group these object or collect object with specified key, this can suddenly become tricky with large dataset.

This plugin has been created to help with this situation.

#Installation

to install run npm install --save realjay-array-group

in your main.js

import Vue from "vue";
import groupArray from "realjay-array-group";

Vue.use(groupArray);

in your component you can then use

let array=[
            {month:1,amount:2000,user_id:1,name:'John Doe'},
            {month:2,amount:5000,user_id:2,name:'Mark Chuks'},
            {month:3,amount:3000,user_id:3,name:'Peter James'},
            {month:1,amount:10000,user_id:2,name:'Mark Chuks'},
            {month:1,amount:4000,user_id:1,name:'John Doe'},
            {month:1,amount:7000,user_id:2,name:'Mark Chuks'},
            {month:3,amount:5000,user_id:1,name:'John Doe'},
            {month:3,amount:6000,user_id:2,name:'Mark Chuks'}
        ];

let grouped=this.$group_array(array,'name','object');
console.log(grouped)

Fint it on the Github Link

usage format

this.$group_array(array,key,format)
ParameterTypeDescriptionDefault
arrayarrayThis is the array of objects that you want to groupnone
keystringThe key to group bynone
formatstringThe format to return the result in. available options are array and objectobject
0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago