Jump to content
php.lv forumi

Question

Posted

Nepieciešama funkcija JSON array filtrēšanai ar JavaScriptu. Augošā, dilstošā secībā.

Tā lai saprot nulles priekša, lielos/mazo burtus, komatus, ja vienā ailē ir gan cipari, gan tekts utt...

 

Meklēju citīgi otro dienu, bet neko sakarīgu nevaru atrast. Varbūt kāds var ieteikt, ko pats lieto?

 

3 answers to this question

Recommended Posts

  • 0
Posted

Kāds vēl underscore, lai veiktu prastu sortēšanu??

Lūdzu, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Uzraksti vnk savu callback funkciju, kas veic salīdzināšanu. 10 min darbs.

 

Drīz moš iekļausim React + Backbone, lai saskaitītu divus mainīgos?

 

var items = [
  { name: 'Edward', value: 21 },
  { name: 'Sharpe', value: 37 },
  { name: 'And', value: 45 },
  { name: 'The', value: -12 },
  { name: 'Magnetic' },
  { name: 'Zeros', value: 37 }
];
items.sort(function (a, b) {
  if (a.name > b.name) {
    return 1;
  }
  if (a.name < b.name) {
    return -1;
  }
  // a must be equal to b
  return 0;
});

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...