I want the push elements of an API into my array if the condition for an attribute is true. So k_api_hash['awsaccounts'][i]['sandman'] will return true or false and, if the condition is true, I want to push the account number in to an array; (k_api_hash['awsaccounts'][i]['accountnumber']) will return an account number.
Code:
k_api_hash = JSON.parse(kens_api)
aws_account_size = k_api_hash["awsaccounts"].size
aws_account_array = []
i = 0
while i < aws_account_size
if k_api_hash['awsaccounts'][i]['sandman'] == "true"
aws_account_array.push(k_api_hash['awsaccounts'][i]['accountnumber'])
i += 1
else
i += 1
end
end
puts "Here are all the aws accounts"
puts aws_account_array.inspect
The problem is that it is returning null value, but successfully pushes the account numbers into the array if the if condition is taken out.
Output:
Here are all the aws accounts
[]