troubleshooting Question

Copy an object of an array in the same array?

Avatar of Conrado ZAVALA
Conrado ZAVALAFlag for Honduras asked on
JavaScriptjQuery
7 Comments2 Solutions232 ViewsLast Modified:
Dear Experts,

I was wondering on how to make a exact copy of an object (index) of an array inside the same array.
For example:

I got this array:
array[0] = { id: gr, name: green, number: 1};
array[1] = { id: rd, name: red, number: 2};
array[2] = { id: bl, name: blue, number: 3};

and I want to make an exact copy of array[2] in the same array.
In other words, what I want to do is to add 1 object to the array (array[3]) with exactly the same info of array[2].

so at the end the array will be:
array[0] = { id: gr, name: green, number: 1};
array[1] = { id: rd, name: red, number: 2};
array[2] = { id: bl, name: blue, number: 3};
array[3] = { id: bl, name: blue, number: 3};

It's that possible?

Thanks in Advance.

Best Regards.
ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros