Program JavaScript untuk Mengurutkan Array Objek berdasarkan Nilai Properti

Contoh 1: Urutkan Array berdasarkan Nama Properti // program to sort array by property name function compareName(a, b) { // converting to uppercase to have case-insensitive comparison const name1 = a.name.toUpperCase(); const name2 = b.name.toUpperCase(); let comparison = 0; if (name1 > name2) { comparison = 1; } else if (name1 < name2) { comparison […]

Read more »

Program JavaScript untuk Mengurutkan Kata dalam Urutan Abjad

Contoh: Mengurutkan Kata dalam Urutan Abjad // program to sort words in alphabetical order // take input const string = prompt(‘Enter a sentence: ‘); // converting to an array const words = string.split(‘ ‘); // sort the array elements words.sort(); // display the sorted words console.log(‘The sorted words are:’); for (const element of words) { […]

Read more »

Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/breatgem/widiyanata.com/wp-includes/functions.php on line 4755