const array = require('array-unflatten');
// some array structure like below
const origin = [
{
'card': 1,
'dates[0].date': new Date(),
'dates[0].quantity': 3,
'dates[1].date': new Date(),
'dates[1].quantity': 4,
'dates[2].date': new Date(),
'dates[2].quantity': 4,
},
{
card: 2,
'dates[0].date': new Date(),
'dates[0].quantity': 4,
},
];
// applying unflatten
const result = array.unflatten(origin);
// results
console.log(result);
/*
result:
[
{
"card": 1,
"dates": [
{
"quantity": 3,
"date": "2018-05-22T17:01:52.213Z"
},
{
"quantity": 4,
"date": "2018-05-22T17:01:52.213Z"
},
{
"quantity": 4,
"date": "2018-05-22T17:01:52.213Z"
},
]
},
{
"card": 2,
"dates": [
{
"quantity": 4,
"date": "2018-05-22T17:01:52.213Z"
}
]
}
]
*/
-
Notifications
You must be signed in to change notification settings - Fork 0
dilterporto/array-unflatten
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published