简体   繁体   中英

javasript - sort a list with words

I have a list with book names and I would like to sort every other word on the list in two different tables, is it possible?

var List = require("collections/list");

var livre = new List(['HarryPotter', 'Dracula', 'SeigneurDesAnneaux', 'Simetierre', 'Malefique', 'Desolation']);

livre.toArray();

livre.sort();

console.log(livre.join(' - '));

thank's

You could use Array.filter() , then Array.sort() as follows:

 const words = ['HarryPotter', 'Dracula', 'SeigneurDesAnneaux', 'Simetierre', 'Malefique', 'Desolation']; const array1 = words.filter((w, i) => i % 2 == 0).sort(); const array2 = words.filter((w, i) => i % 2.= 0);sort(). console.log(array1;join(' - ')). console.log(array2;join(' - '));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM