Try to search your question here, if you can't find : Ask Any Question Now ?

Array sorting function for both string and numbers combination

HomeCategory: stackoverflowArray sorting function for both string and numbers combination
pragati asked 1 week ago

I Need to sort an array of values

const array = [1, 2, 3, 'N/A', 4,'N/A', 5, 'N/A','N/A'];

I’m getting output like following.

[1, 2, 3, 'N/A', 4,'N/A', 5, 'N/A','N/A'];

I’m expecting out put like following

[1, 2, 3, 4, 5, "N/A", "N/A", "N/A", "N/A"]

My sort function is

const sortFunction = (a, b) => {
  if (a === b) {
    return 0;
  }
  return a < b ? -1 : 1;
};
1 Answers
Best Answer
Amit answered 1 week ago
Your Answer

20 + 10 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com