You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将单对象数组内的对象值拼接为带空格的单个字符串

单对象数组属性值拼接方案

需求说明

现有仅包含1个对象的数组如下:

[
   {
      "key1":"john",
      "key2":"smith",
      "key3":"mark"
   }
]

需要将对象的所有属性值用空格分隔拼接为单个字符串,最终得到结果:

john smith mark


不同语言实现示例

JavaScript

// 原始数据
const originArr = [
   {
      "key1":"john",
      "key2":"smith",
      "key3":"mark"
   }
]
// 处理逻辑:先取数组第一个元素,提取所有属性值后用空格拼接
const res = Object.values(originArr[0]).join(' ')
console.log(res) // 输出 john smith mark

Python

# 原始数据
origin_arr = [
   {
      "key1":"john",
      "key2":"smith",
      "key3":"mark"
   }
]
# 处理逻辑:先取数组第一个元素,提取所有值后用空格拼接
res = ' '.join(origin_arr[0].values())
print(res) # 输出 john smith mark

PHP

// 原始数据
$originArr = [
    [
        'key1' => 'john',
        'key2' => 'smith',
        'key3' => 'mark'
    ]
];
// 处理逻辑
$res = implode(' ', array_values($originArr[0]));
echo $res; // 输出 john smith mark

内容的提问来源于stack exchange,提问作者Adnan Farogh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 10:18:03