Reputation: 317
I have two arrays:
arrayNumberNames=['one', 'two', 'three']
arrayDigits=[1,2,3]
I want to combine them into an array that looks like this:
arrayNumbers=[
{
name: 'one'
digit: 1,
},
{
name: 'two'
digit: 2,
},
{
name: 'three'
digit: 3,
}
]
Upvotes: 0
Views: 77
Reputation: 7277
In bash you can create associative array like this:
declare -A arrayNumbers
And populate it like this
for i in ${arrayDigits[@]}; { arrayNumbers[${arrayNumberNames[$i]}]=$i; }
Array will look like this
arrayNumbers=( [one]=1 [two]=2 [three]=3 )
Upvotes: 2