本文介绍了从键和值数组创建对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将头撞在墙上好几个小时了,但似乎找不到办法.我有一个键数组和一个值数组,如何生成对象?输入:

I've been banging my head against the wall for several hours on this and just can't seem to find a way to do this. I have an array of keys and an array of values, how can I generate an object? Input:

[["key1", "key2"], ["val1", "val2"]]

输出:

{"key1": "val1", "key2": "val2"}

推荐答案

github 上解决了此问题a>:

Resolved this on github:

.[0] as $keys |
.[1] as $values |
reduce range(0; $keys|length) as $i  ( {}; . + { ($keys[$i]): $values[$i] })

这篇关于从键和值数组创建对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!