Simple sorting algorithm on an object JS
- or -
Post a project like this2067
£20(approx. $25)
- Posted:
- Proposals: 1
- Remote
- #2101841
- Awarded
Description
Experience Level: Entry
Hello,
I have this object:
object : {
haha: {name:'lskda', value:'sdfasdf},
hehe: {name:'gfdgfd', value: 'sdfdsf'},
hoho: {name:'dsfdsf', 'fsdfs'},
hihi: {name:'fsdfdsf', value:'gsfdsfsd'},
dodo:{name:'dsfdsfdsf', value:'dsfdsfdsf'},
dada:{name:'dsfdsfdsf', value:'dsfdsfdsf'},
}
and I want to sort this object based on this array in that order: array = ['dodo', 'hehe', 'hoho', 'hihi', 'haha']
to look like this:
object : {
dodo:{name:'dsfdsfdsf', value:'dsfdsfdsf'},
hehe: {name:'gfdgfd', value: 'sdfdsf'},
hoho: {name:'dsfdsf', 'fsdfs'},
hihi: {name:'fsdfdsf', value:'gsfdsfsd'},
haha: {name:'lskda', value:'sdfasdf},
}
please keep in mind that the array and object are both dynamic and values could be anything
I have this object:
object : {
haha: {name:'lskda', value:'sdfasdf},
hehe: {name:'gfdgfd', value: 'sdfdsf'},
hoho: {name:'dsfdsf', 'fsdfs'},
hihi: {name:'fsdfdsf', value:'gsfdsfsd'},
dodo:{name:'dsfdsfdsf', value:'dsfdsfdsf'},
dada:{name:'dsfdsfdsf', value:'dsfdsfdsf'},
}
and I want to sort this object based on this array in that order: array = ['dodo', 'hehe', 'hoho', 'hihi', 'haha']
to look like this:
object : {
dodo:{name:'dsfdsfdsf', value:'dsfdsfdsf'},
hehe: {name:'gfdgfd', value: 'sdfdsf'},
hoho: {name:'dsfdsf', 'fsdfs'},
hihi: {name:'fsdfdsf', value:'gsfdsfsd'},
haha: {name:'lskda', value:'sdfasdf},
}
please keep in mind that the array and object are both dynamic and values could be anything
Alex C.
100% (11)Projects Completed
12
Freelancers worked with
12
Projects awarded
50%
Last project
23 Aug 2018
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
What sort of object is it ? PHP or JSON
-
Hi, i have a question...
Are the members of the array always named as the keys in the object? -
Is your object structure flexible? Your current object isn't a valid JavaScript object.
690512690499690489
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies