Is there a way to develop a function that can organize an array of data based on the value of a specified field? Suppose the field consists of three numbers: 1, 2, 3. The idea is that upon providing a certain value to the function, it will rearrange the table accordingly. Here is an example array with console.log output:
0: {id: '1', name: 'Example', location: 'Example', key: 'Example', edit: '0'}
1: {id: '2', name: 'Example', location: 'Example', key: 'Example', edit: '0'}
2: {id: '2', name: 'Example', location: 'Example', key: 'Example', edit: '0'}
3: {id: '3', name: 'Example', location: 'Example', key: 'Example', edit: '0'}
For instance, if I wish to sort the array by an id
of two, the sorted output would be as follows:
0: {id: '2', name: 'Example', location: 'Example', key: 'Example', edit: '0'}
1: {id: '2', name: 'Example', location: 'Example', key: 'Example', edit: '0'}
2: {id: '1', name: 'Example', location: 'Example', key: 'Example', edit: '0'}
3: {id: '3', name: 'Example', location: 'Example', key: 'Example', edit: '0'}
What steps should I take in order to accomplish this sorting task or where should I begin?