Split object into multiple ordered arrays based on identity of 1 spesific value
Not quite sure if that title was the best I could do.
I'm a pretty new to js and keep running into problems ... I hope some of you have the time to give me a pointer or two on this scenario.
I have several objects that looks pretty much like this - except from the fact that there are 28 instances of every "room" type. I need to split this object into multiple objects - one for each "room" type. In some of my objects there are only one room type - whilst in others there are 3 or 4.
[ { id: 1
created: 2018-12-29T13:18:05.788Z,
room: 'Double Room'
type: 'Standard'
price: 500
},
{ id: 29
created: 2018-12-29T13:18:05.788Z,
room: 'Twin Room'
type: 'Standard'
price: 500
},
{ id: 58
created: 2018-12-29T13:18:05.788Z,
room: 'Family Room'
type: 'Standard'
price: 900
},
]
Oh, and it's important that the instances don't "loose" their order in the array - since it's date related and need to be presentet in an ascending order. And vanilla js only.
Is array.map() the function I'm looking for to solve this problem? Is it posible to do this without iteration?
My final goal is to create some kind of generic function that can sort this out for all my objects.
And guys: happy hollidays!
javascript arrays sorting
add a comment |
Not quite sure if that title was the best I could do.
I'm a pretty new to js and keep running into problems ... I hope some of you have the time to give me a pointer or two on this scenario.
I have several objects that looks pretty much like this - except from the fact that there are 28 instances of every "room" type. I need to split this object into multiple objects - one for each "room" type. In some of my objects there are only one room type - whilst in others there are 3 or 4.
[ { id: 1
created: 2018-12-29T13:18:05.788Z,
room: 'Double Room'
type: 'Standard'
price: 500
},
{ id: 29
created: 2018-12-29T13:18:05.788Z,
room: 'Twin Room'
type: 'Standard'
price: 500
},
{ id: 58
created: 2018-12-29T13:18:05.788Z,
room: 'Family Room'
type: 'Standard'
price: 900
},
]
Oh, and it's important that the instances don't "loose" their order in the array - since it's date related and need to be presentet in an ascending order. And vanilla js only.
Is array.map() the function I'm looking for to solve this problem? Is it posible to do this without iteration?
My final goal is to create some kind of generic function that can sort this out for all my objects.
And guys: happy hollidays!
javascript arrays sorting
To get the best answers to your question we like to see a) that you've attempted to solve the problem yourself first, and b) used a Minimal, Complete, and Verifiable example to narrow down the problem. Here's a question checklist you might find useful.. See also the site help section on how to ask a good question.
– Andy
Dec 29 '18 at 18:33
Are you saying you have an array of objects representing groups of rooms, that you want pulled out of the array? I assume you further have more of these arrays of room objects. Do you want a single flat array of all room objects in some order? Do you want an object of room type as key and array of matching room objects, in some order? Can you provide an example expected output?
– Drew Reese
Dec 29 '18 at 18:45
I basically have 1 array of objects representing room prices for the next 28 days - for one spesific hotel. Furtheremore there are multiple hotels - so multiple arrays. Since I need to make price comparisons - I need to list them out sorted by room type - so that I can compare price between two different hotels on a spesific date - and the same room type ... Since it's all going to be listed in an html table - I suspect it would be most conveniant to have multiple arrays with 1 single room type? Did that make sense?
– Jonas__G
Dec 29 '18 at 19:05
add a comment |
Not quite sure if that title was the best I could do.
I'm a pretty new to js and keep running into problems ... I hope some of you have the time to give me a pointer or two on this scenario.
I have several objects that looks pretty much like this - except from the fact that there are 28 instances of every "room" type. I need to split this object into multiple objects - one for each "room" type. In some of my objects there are only one room type - whilst in others there are 3 or 4.
[ { id: 1
created: 2018-12-29T13:18:05.788Z,
room: 'Double Room'
type: 'Standard'
price: 500
},
{ id: 29
created: 2018-12-29T13:18:05.788Z,
room: 'Twin Room'
type: 'Standard'
price: 500
},
{ id: 58
created: 2018-12-29T13:18:05.788Z,
room: 'Family Room'
type: 'Standard'
price: 900
},
]
Oh, and it's important that the instances don't "loose" their order in the array - since it's date related and need to be presentet in an ascending order. And vanilla js only.
Is array.map() the function I'm looking for to solve this problem? Is it posible to do this without iteration?
My final goal is to create some kind of generic function that can sort this out for all my objects.
And guys: happy hollidays!
javascript arrays sorting
Not quite sure if that title was the best I could do.
I'm a pretty new to js and keep running into problems ... I hope some of you have the time to give me a pointer or two on this scenario.
I have several objects that looks pretty much like this - except from the fact that there are 28 instances of every "room" type. I need to split this object into multiple objects - one for each "room" type. In some of my objects there are only one room type - whilst in others there are 3 or 4.
[ { id: 1
created: 2018-12-29T13:18:05.788Z,
room: 'Double Room'
type: 'Standard'
price: 500
},
{ id: 29
created: 2018-12-29T13:18:05.788Z,
room: 'Twin Room'
type: 'Standard'
price: 500
},
{ id: 58
created: 2018-12-29T13:18:05.788Z,
room: 'Family Room'
type: 'Standard'
price: 900
},
]
Oh, and it's important that the instances don't "loose" their order in the array - since it's date related and need to be presentet in an ascending order. And vanilla js only.
Is array.map() the function I'm looking for to solve this problem? Is it posible to do this without iteration?
My final goal is to create some kind of generic function that can sort this out for all my objects.
And guys: happy hollidays!
javascript arrays sorting
javascript arrays sorting
asked Dec 29 '18 at 18:28
Jonas__GJonas__G
1917
1917
To get the best answers to your question we like to see a) that you've attempted to solve the problem yourself first, and b) used a Minimal, Complete, and Verifiable example to narrow down the problem. Here's a question checklist you might find useful.. See also the site help section on how to ask a good question.
– Andy
Dec 29 '18 at 18:33
Are you saying you have an array of objects representing groups of rooms, that you want pulled out of the array? I assume you further have more of these arrays of room objects. Do you want a single flat array of all room objects in some order? Do you want an object of room type as key and array of matching room objects, in some order? Can you provide an example expected output?
– Drew Reese
Dec 29 '18 at 18:45
I basically have 1 array of objects representing room prices for the next 28 days - for one spesific hotel. Furtheremore there are multiple hotels - so multiple arrays. Since I need to make price comparisons - I need to list them out sorted by room type - so that I can compare price between two different hotels on a spesific date - and the same room type ... Since it's all going to be listed in an html table - I suspect it would be most conveniant to have multiple arrays with 1 single room type? Did that make sense?
– Jonas__G
Dec 29 '18 at 19:05
add a comment |
To get the best answers to your question we like to see a) that you've attempted to solve the problem yourself first, and b) used a Minimal, Complete, and Verifiable example to narrow down the problem. Here's a question checklist you might find useful.. See also the site help section on how to ask a good question.
– Andy
Dec 29 '18 at 18:33
Are you saying you have an array of objects representing groups of rooms, that you want pulled out of the array? I assume you further have more of these arrays of room objects. Do you want a single flat array of all room objects in some order? Do you want an object of room type as key and array of matching room objects, in some order? Can you provide an example expected output?
– Drew Reese
Dec 29 '18 at 18:45
I basically have 1 array of objects representing room prices for the next 28 days - for one spesific hotel. Furtheremore there are multiple hotels - so multiple arrays. Since I need to make price comparisons - I need to list them out sorted by room type - so that I can compare price between two different hotels on a spesific date - and the same room type ... Since it's all going to be listed in an html table - I suspect it would be most conveniant to have multiple arrays with 1 single room type? Did that make sense?
– Jonas__G
Dec 29 '18 at 19:05
To get the best answers to your question we like to see a) that you've attempted to solve the problem yourself first, and b) used a Minimal, Complete, and Verifiable example to narrow down the problem. Here's a question checklist you might find useful.. See also the site help section on how to ask a good question.
– Andy
Dec 29 '18 at 18:33
To get the best answers to your question we like to see a) that you've attempted to solve the problem yourself first, and b) used a Minimal, Complete, and Verifiable example to narrow down the problem. Here's a question checklist you might find useful.. See also the site help section on how to ask a good question.
– Andy
Dec 29 '18 at 18:33
Are you saying you have an array of objects representing groups of rooms, that you want pulled out of the array? I assume you further have more of these arrays of room objects. Do you want a single flat array of all room objects in some order? Do you want an object of room type as key and array of matching room objects, in some order? Can you provide an example expected output?
– Drew Reese
Dec 29 '18 at 18:45
Are you saying you have an array of objects representing groups of rooms, that you want pulled out of the array? I assume you further have more of these arrays of room objects. Do you want a single flat array of all room objects in some order? Do you want an object of room type as key and array of matching room objects, in some order? Can you provide an example expected output?
– Drew Reese
Dec 29 '18 at 18:45
I basically have 1 array of objects representing room prices for the next 28 days - for one spesific hotel. Furtheremore there are multiple hotels - so multiple arrays. Since I need to make price comparisons - I need to list them out sorted by room type - so that I can compare price between two different hotels on a spesific date - and the same room type ... Since it's all going to be listed in an html table - I suspect it would be most conveniant to have multiple arrays with 1 single room type? Did that make sense?
– Jonas__G
Dec 29 '18 at 19:05
I basically have 1 array of objects representing room prices for the next 28 days - for one spesific hotel. Furtheremore there are multiple hotels - so multiple arrays. Since I need to make price comparisons - I need to list them out sorted by room type - so that I can compare price between two different hotels on a spesific date - and the same room type ... Since it's all going to be listed in an html table - I suspect it would be most conveniant to have multiple arrays with 1 single room type? Did that make sense?
– Jonas__G
Dec 29 '18 at 19:05
add a comment |
1 Answer
1
active
oldest
votes
You could take an object as hash table for the wanted groups. Then iterate the objects and assign the object to the group. If the group does not exist, create a new group with an array.
function groupBy(array, key) {
var groups = Object.create(null);
array.forEach(o => (groups[o[key]] = groups[o[key]] || ).push(o));
return groups;
}
var data = [{ id: 1, created: '2018-12-29T13:18:05.788Z', room: 'Double Room', type: 'Standard', price: 500 }, { id: 29, created: '2018-12-29T13:18:05.788Z', room: 'Twin Room', type: 'Standard', price: 500 }, { id: 58, created: '2018-12-29T13:18:05.788Z', room: 'Family Room', type: 'Standard', price: 900 }],
groupedByRoom = groupBy(data, 'room');
console.log(groupedByRoom);.as-console-wrapper { max-height: 100% !important; top: 0; }
That looks really cool and I would never have come up with anything remotely like it. Reading your code, I only understand half of it - but now I'm motivated to study the rest to a point where I do understand it. I do understand Andy 's comment above though - but when you really don't know where to start it's not much help. With @Nina 's answer here I'm able to keep grinding. My initial "idea" was "iterate and find identical values in that 1 key, store them and generate new arrays where key = that spesific value". Mind you; I don't really know how to do that either. Thanks Nina!!!
– Jonas__G
Dec 29 '18 at 18:52
Can I ask a quick follow up, @Nina? I'm just learning about hash tables now, so this is a little new to me. I was thinking of expanding that function to also filter out items with certain values, but I guess I'll then have to create a function inside the forEach and use array.filter()? And does it make sence to convert the result back using Object.entries() to simplify the iteration I need to do in my ejs-file later? Sorry if these are stupid questions. Too many "un-organized" concepts in my head at the moment since I'm new to most of them.
– Jonas__G
Dec 31 '18 at 14:07
@Jonas__G, you can ask. but i think it's a good idea, to ask a new question, where you have space for presenting the code, even the pseudo code and add some data, the idea of what you want and the result, which is often missing in the question ...
– Nina Scholz
Dec 31 '18 at 14:14
1
True that. Happy new year, @Nina.
– Jonas__G
Dec 31 '18 at 14:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53972264%2fsplit-object-into-multiple-ordered-arrays-based-on-identity-of-1-spesific-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could take an object as hash table for the wanted groups. Then iterate the objects and assign the object to the group. If the group does not exist, create a new group with an array.
function groupBy(array, key) {
var groups = Object.create(null);
array.forEach(o => (groups[o[key]] = groups[o[key]] || ).push(o));
return groups;
}
var data = [{ id: 1, created: '2018-12-29T13:18:05.788Z', room: 'Double Room', type: 'Standard', price: 500 }, { id: 29, created: '2018-12-29T13:18:05.788Z', room: 'Twin Room', type: 'Standard', price: 500 }, { id: 58, created: '2018-12-29T13:18:05.788Z', room: 'Family Room', type: 'Standard', price: 900 }],
groupedByRoom = groupBy(data, 'room');
console.log(groupedByRoom);.as-console-wrapper { max-height: 100% !important; top: 0; }
That looks really cool and I would never have come up with anything remotely like it. Reading your code, I only understand half of it - but now I'm motivated to study the rest to a point where I do understand it. I do understand Andy 's comment above though - but when you really don't know where to start it's not much help. With @Nina 's answer here I'm able to keep grinding. My initial "idea" was "iterate and find identical values in that 1 key, store them and generate new arrays where key = that spesific value". Mind you; I don't really know how to do that either. Thanks Nina!!!
– Jonas__G
Dec 29 '18 at 18:52
Can I ask a quick follow up, @Nina? I'm just learning about hash tables now, so this is a little new to me. I was thinking of expanding that function to also filter out items with certain values, but I guess I'll then have to create a function inside the forEach and use array.filter()? And does it make sence to convert the result back using Object.entries() to simplify the iteration I need to do in my ejs-file later? Sorry if these are stupid questions. Too many "un-organized" concepts in my head at the moment since I'm new to most of them.
– Jonas__G
Dec 31 '18 at 14:07
@Jonas__G, you can ask. but i think it's a good idea, to ask a new question, where you have space for presenting the code, even the pseudo code and add some data, the idea of what you want and the result, which is often missing in the question ...
– Nina Scholz
Dec 31 '18 at 14:14
1
True that. Happy new year, @Nina.
– Jonas__G
Dec 31 '18 at 14:21
add a comment |
You could take an object as hash table for the wanted groups. Then iterate the objects and assign the object to the group. If the group does not exist, create a new group with an array.
function groupBy(array, key) {
var groups = Object.create(null);
array.forEach(o => (groups[o[key]] = groups[o[key]] || ).push(o));
return groups;
}
var data = [{ id: 1, created: '2018-12-29T13:18:05.788Z', room: 'Double Room', type: 'Standard', price: 500 }, { id: 29, created: '2018-12-29T13:18:05.788Z', room: 'Twin Room', type: 'Standard', price: 500 }, { id: 58, created: '2018-12-29T13:18:05.788Z', room: 'Family Room', type: 'Standard', price: 900 }],
groupedByRoom = groupBy(data, 'room');
console.log(groupedByRoom);.as-console-wrapper { max-height: 100% !important; top: 0; }
That looks really cool and I would never have come up with anything remotely like it. Reading your code, I only understand half of it - but now I'm motivated to study the rest to a point where I do understand it. I do understand Andy 's comment above though - but when you really don't know where to start it's not much help. With @Nina 's answer here I'm able to keep grinding. My initial "idea" was "iterate and find identical values in that 1 key, store them and generate new arrays where key = that spesific value". Mind you; I don't really know how to do that either. Thanks Nina!!!
– Jonas__G
Dec 29 '18 at 18:52
Can I ask a quick follow up, @Nina? I'm just learning about hash tables now, so this is a little new to me. I was thinking of expanding that function to also filter out items with certain values, but I guess I'll then have to create a function inside the forEach and use array.filter()? And does it make sence to convert the result back using Object.entries() to simplify the iteration I need to do in my ejs-file later? Sorry if these are stupid questions. Too many "un-organized" concepts in my head at the moment since I'm new to most of them.
– Jonas__G
Dec 31 '18 at 14:07
@Jonas__G, you can ask. but i think it's a good idea, to ask a new question, where you have space for presenting the code, even the pseudo code and add some data, the idea of what you want and the result, which is often missing in the question ...
– Nina Scholz
Dec 31 '18 at 14:14
1
True that. Happy new year, @Nina.
– Jonas__G
Dec 31 '18 at 14:21
add a comment |
You could take an object as hash table for the wanted groups. Then iterate the objects and assign the object to the group. If the group does not exist, create a new group with an array.
function groupBy(array, key) {
var groups = Object.create(null);
array.forEach(o => (groups[o[key]] = groups[o[key]] || ).push(o));
return groups;
}
var data = [{ id: 1, created: '2018-12-29T13:18:05.788Z', room: 'Double Room', type: 'Standard', price: 500 }, { id: 29, created: '2018-12-29T13:18:05.788Z', room: 'Twin Room', type: 'Standard', price: 500 }, { id: 58, created: '2018-12-29T13:18:05.788Z', room: 'Family Room', type: 'Standard', price: 900 }],
groupedByRoom = groupBy(data, 'room');
console.log(groupedByRoom);.as-console-wrapper { max-height: 100% !important; top: 0; }You could take an object as hash table for the wanted groups. Then iterate the objects and assign the object to the group. If the group does not exist, create a new group with an array.
function groupBy(array, key) {
var groups = Object.create(null);
array.forEach(o => (groups[o[key]] = groups[o[key]] || ).push(o));
return groups;
}
var data = [{ id: 1, created: '2018-12-29T13:18:05.788Z', room: 'Double Room', type: 'Standard', price: 500 }, { id: 29, created: '2018-12-29T13:18:05.788Z', room: 'Twin Room', type: 'Standard', price: 500 }, { id: 58, created: '2018-12-29T13:18:05.788Z', room: 'Family Room', type: 'Standard', price: 900 }],
groupedByRoom = groupBy(data, 'room');
console.log(groupedByRoom);.as-console-wrapper { max-height: 100% !important; top: 0; }function groupBy(array, key) {
var groups = Object.create(null);
array.forEach(o => (groups[o[key]] = groups[o[key]] || ).push(o));
return groups;
}
var data = [{ id: 1, created: '2018-12-29T13:18:05.788Z', room: 'Double Room', type: 'Standard', price: 500 }, { id: 29, created: '2018-12-29T13:18:05.788Z', room: 'Twin Room', type: 'Standard', price: 500 }, { id: 58, created: '2018-12-29T13:18:05.788Z', room: 'Family Room', type: 'Standard', price: 900 }],
groupedByRoom = groupBy(data, 'room');
console.log(groupedByRoom);.as-console-wrapper { max-height: 100% !important; top: 0; }function groupBy(array, key) {
var groups = Object.create(null);
array.forEach(o => (groups[o[key]] = groups[o[key]] || ).push(o));
return groups;
}
var data = [{ id: 1, created: '2018-12-29T13:18:05.788Z', room: 'Double Room', type: 'Standard', price: 500 }, { id: 29, created: '2018-12-29T13:18:05.788Z', room: 'Twin Room', type: 'Standard', price: 500 }, { id: 58, created: '2018-12-29T13:18:05.788Z', room: 'Family Room', type: 'Standard', price: 900 }],
groupedByRoom = groupBy(data, 'room');
console.log(groupedByRoom);.as-console-wrapper { max-height: 100% !important; top: 0; }answered Dec 29 '18 at 18:37
Nina ScholzNina Scholz
180k1493160
180k1493160
That looks really cool and I would never have come up with anything remotely like it. Reading your code, I only understand half of it - but now I'm motivated to study the rest to a point where I do understand it. I do understand Andy 's comment above though - but when you really don't know where to start it's not much help. With @Nina 's answer here I'm able to keep grinding. My initial "idea" was "iterate and find identical values in that 1 key, store them and generate new arrays where key = that spesific value". Mind you; I don't really know how to do that either. Thanks Nina!!!
– Jonas__G
Dec 29 '18 at 18:52
Can I ask a quick follow up, @Nina? I'm just learning about hash tables now, so this is a little new to me. I was thinking of expanding that function to also filter out items with certain values, but I guess I'll then have to create a function inside the forEach and use array.filter()? And does it make sence to convert the result back using Object.entries() to simplify the iteration I need to do in my ejs-file later? Sorry if these are stupid questions. Too many "un-organized" concepts in my head at the moment since I'm new to most of them.
– Jonas__G
Dec 31 '18 at 14:07
@Jonas__G, you can ask. but i think it's a good idea, to ask a new question, where you have space for presenting the code, even the pseudo code and add some data, the idea of what you want and the result, which is often missing in the question ...
– Nina Scholz
Dec 31 '18 at 14:14
1
True that. Happy new year, @Nina.
– Jonas__G
Dec 31 '18 at 14:21
add a comment |
That looks really cool and I would never have come up with anything remotely like it. Reading your code, I only understand half of it - but now I'm motivated to study the rest to a point where I do understand it. I do understand Andy 's comment above though - but when you really don't know where to start it's not much help. With @Nina 's answer here I'm able to keep grinding. My initial "idea" was "iterate and find identical values in that 1 key, store them and generate new arrays where key = that spesific value". Mind you; I don't really know how to do that either. Thanks Nina!!!
– Jonas__G
Dec 29 '18 at 18:52
Can I ask a quick follow up, @Nina? I'm just learning about hash tables now, so this is a little new to me. I was thinking of expanding that function to also filter out items with certain values, but I guess I'll then have to create a function inside the forEach and use array.filter()? And does it make sence to convert the result back using Object.entries() to simplify the iteration I need to do in my ejs-file later? Sorry if these are stupid questions. Too many "un-organized" concepts in my head at the moment since I'm new to most of them.
– Jonas__G
Dec 31 '18 at 14:07
@Jonas__G, you can ask. but i think it's a good idea, to ask a new question, where you have space for presenting the code, even the pseudo code and add some data, the idea of what you want and the result, which is often missing in the question ...
– Nina Scholz
Dec 31 '18 at 14:14
1
True that. Happy new year, @Nina.
– Jonas__G
Dec 31 '18 at 14:21
That looks really cool and I would never have come up with anything remotely like it. Reading your code, I only understand half of it - but now I'm motivated to study the rest to a point where I do understand it. I do understand Andy 's comment above though - but when you really don't know where to start it's not much help. With @Nina 's answer here I'm able to keep grinding. My initial "idea" was "iterate and find identical values in that 1 key, store them and generate new arrays where key = that spesific value". Mind you; I don't really know how to do that either. Thanks Nina!!!
– Jonas__G
Dec 29 '18 at 18:52
That looks really cool and I would never have come up with anything remotely like it. Reading your code, I only understand half of it - but now I'm motivated to study the rest to a point where I do understand it. I do understand Andy 's comment above though - but when you really don't know where to start it's not much help. With @Nina 's answer here I'm able to keep grinding. My initial "idea" was "iterate and find identical values in that 1 key, store them and generate new arrays where key = that spesific value". Mind you; I don't really know how to do that either. Thanks Nina!!!
– Jonas__G
Dec 29 '18 at 18:52
Can I ask a quick follow up, @Nina? I'm just learning about hash tables now, so this is a little new to me. I was thinking of expanding that function to also filter out items with certain values, but I guess I'll then have to create a function inside the forEach and use array.filter()? And does it make sence to convert the result back using Object.entries() to simplify the iteration I need to do in my ejs-file later? Sorry if these are stupid questions. Too many "un-organized" concepts in my head at the moment since I'm new to most of them.
– Jonas__G
Dec 31 '18 at 14:07
Can I ask a quick follow up, @Nina? I'm just learning about hash tables now, so this is a little new to me. I was thinking of expanding that function to also filter out items with certain values, but I guess I'll then have to create a function inside the forEach and use array.filter()? And does it make sence to convert the result back using Object.entries() to simplify the iteration I need to do in my ejs-file later? Sorry if these are stupid questions. Too many "un-organized" concepts in my head at the moment since I'm new to most of them.
– Jonas__G
Dec 31 '18 at 14:07
@Jonas__G, you can ask. but i think it's a good idea, to ask a new question, where you have space for presenting the code, even the pseudo code and add some data, the idea of what you want and the result, which is often missing in the question ...
– Nina Scholz
Dec 31 '18 at 14:14
@Jonas__G, you can ask. but i think it's a good idea, to ask a new question, where you have space for presenting the code, even the pseudo code and add some data, the idea of what you want and the result, which is often missing in the question ...
– Nina Scholz
Dec 31 '18 at 14:14
1
1
True that. Happy new year, @Nina.
– Jonas__G
Dec 31 '18 at 14:21
True that. Happy new year, @Nina.
– Jonas__G
Dec 31 '18 at 14:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53972264%2fsplit-object-into-multiple-ordered-arrays-based-on-identity-of-1-spesific-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
To get the best answers to your question we like to see a) that you've attempted to solve the problem yourself first, and b) used a Minimal, Complete, and Verifiable example to narrow down the problem. Here's a question checklist you might find useful.. See also the site help section on how to ask a good question.
– Andy
Dec 29 '18 at 18:33
Are you saying you have an array of objects representing groups of rooms, that you want pulled out of the array? I assume you further have more of these arrays of room objects. Do you want a single flat array of all room objects in some order? Do you want an object of room type as key and array of matching room objects, in some order? Can you provide an example expected output?
– Drew Reese
Dec 29 '18 at 18:45
I basically have 1 array of objects representing room prices for the next 28 days - for one spesific hotel. Furtheremore there are multiple hotels - so multiple arrays. Since I need to make price comparisons - I need to list them out sorted by room type - so that I can compare price between two different hotels on a spesific date - and the same room type ... Since it's all going to be listed in an html table - I suspect it would be most conveniant to have multiple arrays with 1 single room type? Did that make sense?
– Jonas__G
Dec 29 '18 at 19:05