【问题标题】:react native - How can get the list of "dog" from the sqlite table?react native - 如何从 sqlite 表中获取“狗”列表?
【发布时间】:2020-11-30 21:26:38
【问题描述】:

如何从“roma”表中获取“dog”列表

表格是:“罗马” 字段是:“toto” 内容是:[{"yoga":63,"dog":"BOB22"},{"yoga":22,"dog":"dragon"}]

所以我想得到“BOB22”和“龙”

【问题讨论】:

  • 您的 JSON 看起来不太正确。你有重复的瑜伽和狗钥匙。
  • 我修复了你可以看到的 json
  • 您是在寻找字符串数组的结果吗?

标签: javascript reactjs sqlite react-native expo


【解决方案1】:

如果您正在寻找 ["BOB22", "dragon"],您可以使用 Array.map 函数来选择您希望添加到新数组的键值。在这种情况下,您需要entry.dog

  const toto = [
    { yoga: 63, dog: "BOB22" },
    { yoga: 22, dog: "dragon" }
  ];
  const dogs = toto.map((entry) => entry.dog);
  console.log(dogs); // print ["BOB22", "dragon"]

对于toto数组中的每一项“entry”,只从toto数组中的每一项中选择“dog”,并将包含每个“dog”项的新数组返回到“dogs”数组中

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-04-01
  • 2010-10-10
  • 2020-12-04
  • 2021-02-17
  • 1970-01-01
  • 2019-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多