如何将新的关联数组添加到现有的关联数组 [英] How to add new associative array to existing associative array

查看:64
本文介绍了如何将新的关联数组添加到现有的关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想知道是否有人知道如何将新的关联数组添加到现有的关联数组中,这是我已经拥有的内容

我有一个包含此值的变量myAray

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"}];



如您所见,我的myArray变量现在只有6个内容,我想在其中添加一个新的关联数组,其值为this



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"}];



但是我该怎么做到呢?我已经尝试过使用myArray.push了,但是并没有解决我的问题.



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

推荐答案

如何在循环中一个接一个地添加新元素?另外,您还应确保新元素具有不同的键和/或决定如果新元素具有目标数组中已使用的键之一但值不同(跳过,替换或其他操作)时该怎么做.

—SA
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


这篇关于如何将新的关联数组添加到现有的关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆