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 lengthjuktoKoro()adds an item to the endsuruThekeJuktoKoro()adds an item at the beginningachheKi()checks whether an item existsberKoro()removes an item from the endsuruThekeKato()removes an item from the beginningrupantor()transforms the array valueschinhitoKoro()filters matching valueskhujo()searches for a valueshajao()sorts the arrayulotoKoro()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:
- Create the array
- Check its size
- Add a new value
- Remove values from either end
- Search for specific items
- Loop through the array
- 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:
- Add a new value to an array
- Remove the first value from an array
- Check whether an item exists
- 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.