const data = [
{ id: 1, name: 'John', location: 'London' },
{ id: 2, name: 'Alice', location: 'New York' },
{ id: 3, name: 'Bob', location: 'Paris' },
{ id: 4, name: 'Jane', location: 'Tokyo' },
];
const selectedLocation = localStorage.getItem('selectedLocation');
const sortedData = data.sort((a, b) => {
if (a.location === selectedLocation && b.location !== selectedLocation) {
return -1;
} else if (a.location !== selectedLocation && b.location === selectedLocation) {
return 1;
} else {
return a.id - b.id;
}
});
console.log(sortedData);