# Replace int element from another element keeping the original

**URL:** <https://discourse.julialang.org/t/replace-int-element-from-another-element-keeping-the-original/66877>\
**Category:** General Usage\
**Tags:** array, arrays\
**Created:** [August 23, 2021, 9:50pm UTC](https://discourse.julialang.org/t/replace-int-element-from-another-element-keeping-the-original/66877 "2021-08-23T21:50:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Mena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastian_mena/32/22819_2.png) [@Sebastian\_Mena](https://discourse.julialang.org/u/Sebastian_Mena)\
**Post date:** [August 23, 2021, 9:50pm UTC](https://discourse.julialang.org/t/replace-int-element-from-another-element-keeping-the-original/66877/1 "2021-08-23T21:50:58Z")

</div>

Hi, i want to save an array `my_array = [1,2,3,4,5]` and replace a element from `my_array` with a value, but i don’t want to change my principal array.  
For example,

```julia
my_array = [1,2,3,4,5]
replace 2 for 8
new_array = [1,8,3,4,5]

```

Then, if print `my_array = [1,2,3,4,5]` and `new_array = [1,8,3,4,5]`  
Is there a function that does that?

Thanks!

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [August 23, 2021, 9:55pm UTC](https://discourse.julialang.org/t/replace-int-element-from-another-element-keeping-the-original/66877/2 "2021-08-23T21:55:29Z")

</div>

```julia
julia> replace([1, 2, 3, 4, 5], 2 => 8)
5-element Vector{Int64}:
 1
 8
 3
 4
 5

```
