score:0
Accepted answer
you could take the wanted groups first in an array, sort the data and assign the object to the group or to the end of a temp array and get the flat data as result.
var data = [{ name: "elig_database", ready: true }, { name: "elig_rules_service", ready: true }, { name: "elig_gateway", ready: true }, { name: "elig_gateway_latest", ready: true, latest: true }, { name: "elig_service_latest", ready: true, latest: true }, { name: "elig_service", ready: true }, { name: "hdxts", ready: false }, { name: "rules_version", ready: true }],
together = [['gateway'], ['rules'], ['elig_database', 'elig_service']],
groups = { gateway: [], rules: [], elig_database: [] },
temp = [groups.gateway, groups.rules, groups.elig_database],
result;
for (let o of data.sort(({ name: a }, { name: b }) => a.localecompare(b))) {
let target = together.find(a => a.some(v => o.name.includes(v)));
if (target) groups[target[0]].push(o);
else temp.push(o);
}
result = temp.flat();
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Source: stackoverflow.com
Related Query
- Sort an array of objects dynamically javascript
- How to Sort Dates, Numbers, Strings from the array of nested JSON objects in Javascript
- how to make button to sort array of objects alphabetical javascript react
- Sort an array of objects in React and render them
- Sort and group objects alphabetically by first letter Javascript
- How to sort array of objects based on a boolean property?
- how to group array of objects by value in reactjs / javascript
- ReactJS: How do I sort an array of objects based on value of props?
- Dynamically mapping an array of objects to table row
- Sort array by first character then number in JavaScript
- Javascript check if string exists in array of objects
- How to sort a nested array of objects in javascript?
- Adding up the values of an array of objects javascript
- How to get Current week from given array of objects date in javascript
- Fastest way to sort array of objects on the basis of nested key values
- Arrays - Javascript - filter array of objects using input search
- Filter array of objects based on the input passed: Javascript
- Sort list of objects javascript
- how would i aggregate array of objects into groups, dynamically
- Javascript 2 arrays of objects , get a value from one array of objects and assign it to the other array of objects
- How to get array of objects in javascript from an array of dictionaries in python?
- how to group and sort an array of objects
- Spread Array of Objects in JavaScript
- Javascript smart filtering array of objects
- Javascript merging objects within an array based on specific value
- Cannot sort array of objects in react
- Count occurrences in strings of an array of objects in Javascript
- sort array of objects if the object has a property
- Merge array of javascript objects
- How do I sort an array of objects in react and render them?
More Query from same tag
- Invariant Violation: Could not find "store" in either the context or props of "Connect(KnowStatus)". Either wrap the root component in a <Provider>
- ReactifyError: Parse Exception
- How do I load SVGs directly in my React component using webpack?
- Recursive function in Redux/Thunk returning Promise object, not regular object
- Why does React.js not have stateTypes?
- How to disable the css changes made by Link/href
- How to pass props to nested routes in React Router 4?
- Docker, script seems to build and run properly, but cant connect on localhost
- Is there any way to import JavaScript function to React component outside from src folder
- React Hook Form require rules of Controller always triggering
- How to unsubscribe from redux store when component will unmount? How to decorate redux connect?
- Alphabetical comparator Javascript using localeCompare
- React - how to check if a specific field value of an object array contains certain string?
- How to import the image dynamically
- Material-UI TexField Select - different display when expanded
- Redux : store.getState return undefined value
- Material-UI Radio Button with svg circle
- Check for multiple array indexes in react/typescript, whether one exists?
- How to mention users using @ in django
- What is the relationship between the React rendering cycle and the React component lifecycle?
- What does the double ampersand selector '&&' do (overriding root class using makeStyles in Material-UI React)?
- Verify if a phone number exist in firebase app using firebase cloud function
- React Router how to dynamically change search part of url
- React router nested not working
- Datepicker component breaking an edit screen, using @unform and react-datepicker
- how to call function with async await in React function, so I can get the result by sequentially
- Webpack5 + react-refresh-webpack-plugin does not work
- Cannot find name T
- How can I get specific data from HTML in React?
- Extend React Abstract Component in Typescript