Question: Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:

```
      a = [1,2,3,4];
      for (i = 0; i < a.length; i++) {
          a[i] += 7;
      }

```

Maybe using map (but not necessarily)?

Edit:

Or a more interesting example:

```
      a = [{'x':1},{'x':2},{'x':3},{'x':4}];

      for (i = 0; i < a.length; i++) {
          a[i].x += 7;
      }

```

Answer: 
The following will answer your question, assuming your UIImageView used UIViewContentModeAspectFit:

You have to regard the image sizing of the image inside UIImageView. This depends on how you set the contentMode. According your description, I assume you are using UIViewContentModeAspectFit. The resulting image will also be centered in the UIImageView so you also have to consider this for the calculation. 

```
-(CGRect )calculateClientRectOfImageInUIImageView:(UIImageView *)imgView
{
    CGSize imgViewSize=imgView.frame.size;                  // Size of UIImageView
    CGSize imgSize=imgView.image.size;                      // Size of the image, currently displayed

    // Calculate the aspect, assuming imgView.contentMode==UIViewContentModeScaleAspectFit

    CGFloat scaleW = imgViewSize.width / imgSize.width;
    CGFloat scaleH = imgViewSize.height / imgSize.height;
    CGFloat aspect=fmin(scaleW, scaleH);

    CGRect imageRect={ {0,0} , { imgSize.width*=aspect, imgSize.height*=aspect } };

    // Note: the above is the same as :
    // CGRect imageRect=CGRectMake(0,0,imgSize.width*=aspect,imgSize.height*=aspect) I just like this notation better

    // Center image

    imageRect.origin.x=(imgViewSize.width-imageRect.size.width)/2;
    imageRect.origin.y=(imgViewSize.height-imageRect.size.height)/2;

    // Add imageView offset

    imageRect.origin.x+=imgView.frame.origin.x;
    imageRect.origin.y+=imgView.frame.origin.y;

    return(imageRect);
}

```

For a better illustration of the differences between the three content modes, see below:

![enter image description here](https://i.stack.imgur.com/J8evc.png)
**Swift 3.0**

I know its quite late but might help someone in future. Its very simple and inbuilt solution provided by iOS. Just need to: 

`import AVFoundation  

let imageRect = AVMakeRect(aspectRatio: image.size, insideRect: self.imageView.bounds)`