Advertisement
deddyprianto

sort string in object

Jan 31st, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const data = [
  2.   {
  3.     title: "Chapter 10",
  4.   },
  5.   {
  6.     title: "Chapter 1",
  7.   },
  8.   {
  9.     title: "Chapter 2",
  10.   },
  11. ];
  12. let hasil;
  13. data.forEach((title) => {
  14.   const da = data.sort(
  15.     (a, b) =>
  16.       a.title.substring(a.title.indexOf(" ") + 0).trim() -
  17.       b.title.substring(b.title.indexOf(" ") + 0).trim()
  18.   );
  19.   hasil = da;
  20. });
  21. console.log(hasil);
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement