Array Operations

Learn how to add, remove, search, loop, and transform arrays in BornomalaScript.

Array Operations

Once you know how to create an array, the next step is learning what you can do with it.

Arrays are useful because they support many common operations such as adding, removing, searching, and looping through values.

Basic Example

Basic operations include adding, removing, and iterating elements.

dhoro myArr = [
    "item1", "item2", "item3",
    "item4", "item5", "item6"
]

lekho(myArr.doirgho())       

myArr.juktoKoro("item7")
lekho(myArr)                
lekho(myArr.doirgho())   

myArr.suruThekeJuktoKoro("item0")
lekho(myArr)                

lekho(myArr.achheKi("item5"))     

myArr.berKoro()
lekho(myArr)       

myArr.suruThekeKato()
lekho(myArr) 


dhoro newArr = myArr.rupantor("uppercase")
lekho(newArr)   // ["ITEM1", "ITEM2", ...]


dhoro filtered = myArr.chinhitoKoro("3")
lekho(filtered)   // ["item3"]



prottek item erJonno myArr erModdhe {
    lekho(item)
}



myArr.shajao()
lekho(myArr)

myArr.ulotoKoro()
lekho(myArr)



lekho(myArr.khujo("5"))   // "item5"



dhoro myArr = [
    "item1", "item2", "item3",
    "item4"
]

prottek x erJonno myArr erModdhe {
    lekho(x)
    jodi (x == "item2") tahole {
        thamo
    }
}

What These Operations Mean

The example shows several useful array actions:

  • doirgho() gets the array length
  • juktoKoro() adds an item to the end
  • suruThekeJuktoKoro() adds an item at the beginning
  • achheKi() checks whether an item exists
  • berKoro() removes an item from the end
  • suruThekeKato() removes an item from the beginning
  • rupantor() transforms the array values
  • chinhitoKoro() filters matching values
  • khujo() searches for a value
  • shajao() sorts the array
  • ulotoKoro() reverses the array

Why These Operations Matter

In real programs, arrays are rarely static. You often need to update them, search through them, and reshape them as your data changes.

That means array operations are essential for:

  • shopping lists
  • student lists
  • menu items
  • scores and rankings
  • task managers

Step-by-Step Breakdown

Read the example in smaller parts:

  1. Create the array
  2. Check its size
  3. Add a new value
  4. Remove values from either end
  5. Search for specific items
  6. Loop through the array
  7. Stop the loop when a match is found

Try These Variations

Practice with your own array:

dhoro fruits = ["apple", "banana", "orange"]
fruits.juktoKoro("mango")
lekho(fruits)
dhoro scores = [10, 20, 30]
lekho(scores.doirgho())
dhoro names = ["Amina", "Rahim", "Sumon"]
lekho(names.khujo("Rahim"))

Common Mistakes

Beginners often make these mistakes:

  • Forgetting that array methods change the data
  • Searching for the wrong value type
  • Expecting a removed item to stay in the array
  • Using the wrong loop variable name

Practice Task

Try writing programs that:

  1. Add a new value to an array
  2. Remove the first value from an array
  3. Check whether an item exists
  4. Print all values one by one

Quick Checklist

Before moving on, make sure you can:

  • Read the length of an array
  • Add and remove values
  • Search and filter items
  • Loop through the collection

If yes, you understand the core array operations in BornomalaScript.