合并对象中的数组

时间:2018-12-03 21:30:14

标签: json merge jq

我有一个对象,它只是一堆任意键,每个键都有一个数组:

{
  "foo": [
    "hello",
    "world"
  ],
  "bar": [
    "foobar"
  ]
}

如何返回此对象中的合并数组。预期的输出将是:

[
  "hello",
  "world",
  "foobar"
]

2 个答案:

答案 0 :(得分:3)

创建值列表并连接该列表中的元素:

[.[]] | add

创建每个数组中每个元素的列表:

[.[][]]

我更喜欢第一个,因为它在我看来更容易解析。

答案 1 :(得分:1)

概括一下:

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, TextInput, ScrollView} from 'react-native';


import { createStackNavigator, createAppContainer} from 'react-navigation';

import SignIn from './src/pages/SignIn';
import SignUp from './src/pages/SignUp';
import Home from './src/pages/Home';
import Setting from './src/pages/Setting';
import ForgetPassword from './src/pages/ForgetPassword';
import Verification from './src/pages/Verification';

const AppStackNavigation = createStackNavigator(
    {
        SignIn: {screen: SignIn},
        SignUp: {screen: SignUp},
        Home: {screen: Home},
        Setting: {screen: Setting},
        ForgetPassword: {screen: ForgetPassword},
        Verification: {screen: Verification},
    }
)

const AppContainer = createAppContainer(AppStackNavigation);

export default AppContainer;