Imagine having an array filled with various option values, such as:
var options = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grapefruit", "honeydew", "kiwi", "lemon", "mango", "nectarine", "orange", "pear", "quince", "raspberry", "strawberry", "tangerine", "ugli fruit", "vanilla bean", "watermelon", "ximenia", "yellow plum", "zucchini"];
If there was a need to convert these into formatted strings that include their position in the array, like this:
var result = ['1st option is "apple"', '2nd option is "banana", '3rd option is "cherry"', '4th option is "date"',...];
An attempt has been made to achieve most of it using the following code:
var result = [];
for(var i = 0; i < options.length; i++){
result.push((i+1)+' option is "'+options[i]+'"');
}
This code generates strings similar to 1 option is "apple"
. However, adding the correct suffixes ('st', 'nd', 'rd', 'th') based on the position remains a challenge. Assistance in resolving this issue would be greatly appreciated. Thank you!