jQuery map selected object

I am working with JavaScript, could you help me please Here is my problem. I have this object:

var MyObj= [{ a: 0, b: "Zero", c: "x", d: "!" }, { a: 1, b: "One", c: "y", d: "@" }]

I want to change the element of selected object ("a" --> "id") to become like this:

var NewObj= [{ id: 0, b: "Zero", c: "x", d: "!" }, { id: 1, b: "One", c: "y", d: "@" }]

I tried to use $.map() method like this

NewObj= $.map(MyObj, function (obj) {
        return { id: obj.a, b: obj.b, c: obj.c, d:obj.d };

Is there any better way to do this since I only change one element of object?

Answers 1

Related Articles