Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
myArray[key]={};
is changing the source array.
myArray2[i]={};
Experts Exchange Solution brought to you by
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
Start your 7-day free trialFrom novice to tech pro — start learning today.
Experts Exchange Solution brought to you by
Anyway, to answer your question, you use a for loop to build a new array or a for-in loop to build a new object (called an "associative array" in other languages).
As to duplicates keys, if there are any, they will overwrite the previous, unless you add additional code to handle that differently.
Open in new window
Open in new window
Edit: Typo in code corrected.