Is there any of way (other than looping) of extracting a particular property of all objects in an array. So say there in an array of people. I want to extract all their first names into an array.
A nested data structure is an array or object which refers to other arrays or objects, i.e. its values are arrays or objects. Such structures can be accessed by consecutively applying dot or bracket notation. Here is an example: const data = { code: 42, items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }] };
To extract part of an array with JavaScript, we can use the JavaScript array slice method with the start and end index of the array to extract. We call slice on oldArray with the start and end indexes respectively. The end index is excluded from the returned array.
To destructure an array in JavaScript, we use the square brackets [] to store the variable name which will be assigned to the name of the array storing the element.
Key Value coding will help you with that:
NSArray *result = [people valueForKey:@"firstname"];
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