Iggy of Pop of hip hop Iggy of Pop of hip hop - 4 months ago 7
Javascript Question

How do i replace something in array using jquery?

I have got this jquery array

var left=[1,2,3,4];


And i want to replace
3
element with
7
.

Answer

You need to use map function here. Try this:

var left = [1,2,3,4];

result = left.map(function(item) { 
    return item == 3? 7: item;
});