I have two arrays in Objective C and I need to find what index something is so I can insert it in the same place. For instance, lets say I have a "name array" and an "age array". How do I find out what index "charlie" is in the "name array" so I know where to insert his age in the "age" array?
Thanks
To find the position of an element in an array, you use the indexOf() method. This method returns the index of the first occurrence the element that you want to find, or -1 if the element is not found. The following illustrates the syntax of the indexOf() method.
An object representing a static ordered collection, for use instead of an Array constant in cases that require reference semantics.
The index indicates the position of the element within the array (starting from 1) and is either a number or a field containing a number.
The purpose of an array is to store multiple pieces of data of the same type together.
-[NSArray indexOfObject:]
would seem to be the logical choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With