This simple JavaScript script allows you to manage an array of strings, ensuring that each string is added only once, sorted alphabetically, and displays useful information like the current array content and its length.
Prevent Duplicate Entries: Checks if a string is already in the array before adding it. Alphabetical Sorting: Automatically sorts the array alphabetically after each addition. Displays Array and Length: Prints the current state of the array and the number of elements it contains.
JavaScript: Logic for managing the array, checking for duplicates, sorting, and displaying results.
The addString(newString) function accepts a string as input. If the string is not already in the array, it gets added and the array is sorted alphabetically. If the string is a duplicate, a message is logged to indicate the string is already present in the array. After each addition, the updated array and its length are logged to the console.