如果我有这个对象数组。我正在寻找从对象数组中添加缺少的键。对于每个丢失的键,最终数组中应有三个条目,名称字段为空。
myArray = [{id: 1, name: 'John'},
{id: 1, name: 'Ray'},
{id: 1, name: 'Elliot'},
{id: 3, name: 'Elli'},
{id: 3, name: 'Smith'},
{id: 3, name: 'John'}]
my expected output should loook like:
expectedArray = [{id: 1, name: 'John'},
{id: 1, name: 'Ray'},
{id: 1, name: 'Elliot'},
{id: 2, name: ''},
{id: 2, name: ''},
{id: 2, name: ''},
{id: 3, name: 'campbell’},
{id: 3, name: 'Smith'},
{id: 3, name: 'John'},
{id: 4, name: ''},
{id: 4, name: ''},
{id: 4, name: ''}]
我尝试了多种方法来实现此任务,但是我没有做。您能帮我怎么做吗?谢谢。
答案 0 :(得分:0)
我假设您的意思是,如果给定对象的所有属性与在对象列表中找到的对象不同,则将其添加到列表中。
您可以这样做
ssh -i ~/.ssh/mykubevm docker@<kubevm-IP>