function swapString(arr,minIndex,i){
    if(minIndex != i){
        var temp = arr[minIndex];
        arr[minIndex] = arr[i];
        arr[i] = temp;
    }
}

function sortStringArray(arr,n){
    for(let i=0;i<n-1;i++){
       	let min_index = i;
		let minStr = arr[i];
        
        for(let j=i+1;j<n;j++){
            if ((arr[j]).localeCompare(minStr) === -1){
              	minStr = arr[j];
				min_index = j;
            }
        }
         swapString(arr,min_index,i);
    }
}

function printArray(arr,n){
    for(let i=0;i<n;i++){
        console.log(i + ": " + arr[i] );
    }
}


let arr = [ "Zebra","Bharat","Computer","Science" ];
let n = arr.length;

console.log("Array Before Sorting");
printArray(arr,n);
console.log("Array After Sorting");
sortStringArray(arr,n);
printArray(arr,n);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: