How can I call a group of array from a .txt file that is starting from the letter of my current word?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Immanity

I have already an array:

var lines = [acerola, apple, apricots, avocado, banana, blackberry, blackcurrant, blueberry, breadfruit, cantaloupe, carambola, cherimoya, cherry, clementine, coconut, cranberry, durian, elderberry, feijoa, fig, gooseberry, grapefruit, grape, guava, jackfruit, kiwifruit, kumquat, lemon, lime, longan, loquat, lychee, mandarin, mango, mangosteen, mulberry, nectarine, olives, orange, papaya, peach, pear, persimmon, pineapple, pitanga, plantain, plum, pomegranate, prune, pummelo, quince, raspberry, rhubarb, sapodilla, soursop, strawberry, tamarind, tangerine, watermelon]

how can I display all the fruits that started with the letter I choose from?
I kinda making a wordchain game where the answer should start with the last letter of the previous answer. It’s for our research so can you please help me!

:bust_in_silhouette: Reply From: Bush2Tree

var letter = "a"
var possible_answers = []
for answer in lines:
    if(answer[0] == letter):
        possible_answers.append(answer)

This will create a new array called possible_answers that contains all members of lines that begin with the letter “a”. It loops through all members of lines, checks if they begin with the desired starting letter, and if so, adds them to the array possible_answers.

thank you very much

Immanity | 2019-09-14 08:07

Why am I getting "Invalid get index “0” (on base:‘String’)??
please help me!!

Immanity | 2019-10-14 10:06