index
Index access allows you to retrieve and modify elements in arrays, lists, strings, and object properties using square bracket notation[]
. This is fundamental for working with collections and data structures in Soul.
Array Index Access
Access array elements by their numeric index:Negative Index Access
Access elements from the end of arrays:String Index Access
Access individual characters in strings:Object Property Index Access
Access object properties using string keys:Dynamic Index Access
Use variables as indices:Multi-dimensional Arrays
Access nested arrays:Nested Object Access
Access nested object properties:Array of Objects Index Access
Access properties of objects in arrays:Index with Expressions
Use complex expressions as indices:Safe Index Access
Handle index bounds safely:Index in Loops
Use indices in loop constructs:Index Assignment Patterns
Different ways to assign values using indices:Index with Error Handling
Handle index access errors:Index with Object Methods
Use index access with object methods:Index Performance Considerations
Optimize index access:Index Validation
Validate indices before use:Best Practices
- Check bounds: Always validate indices before use
- Use meaningful names:
users[currentIndex]
instead ofusers[i]
- Handle errors: Wrap index access in try-catch when needed
- Cache lengths: Store array lengths in variables for performance
- Use safe access: Create helper functions for safe index operations