Click here to Skip to main content
15,887,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys i was wondering if anyone of you knows how to add a new associative array to an existing associative array here's what i already have

I have a variable myAray which contains this value
myArray["-" + 1] = [{ title: "title 1", key: "1", property: "new"}];
myArray["-" + 2] = [{ title: "title 2", key: "2", property: "old"}];
myArray["-" + 3] = [{ title: "title 3", key: "3", property: "modify"}];
myArray["-" + 4] = [{ title: "title 4", key: "4", property: "few"}];
myArray["-" + 5] = [{ title: "title 5", key: "5", property: "other property"}];
myArray["-" + 6] = [{ title: "title 6", key: "6", property: "streaming"}];


as you can see i only have 6 content for my myArray variable now i would like to add a new associative array in it with a value of this

myArray["-" + 7] = [{ title: "New inserted array", key: "7", property: "newly created"}];


but how do i accomplish that? i already tried using myArray.push but that didnt solve my problem
Posted

1 solution

How about adding new elements in a loop, one by one? Also, you should make sure the new elements have different keys and/or decide what to do if a new element has one of the keys already used in a target array but different value — skip, replace or something else.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900