Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中显示来自对象的数据_Javascript_Arrays_Reactjs_Object - Fatal编程技术网

在Javascript中显示来自对象的数据

在Javascript中显示来自对象的数据,javascript,arrays,reactjs,object,Javascript,Arrays,Reactjs,Object,我有一个包含数据数组的对象 { "success": true, "message": "Merchant and Shop info for auth user", "data": { "merchant": { "status": "Onboarded", "merchant_type":

我有一个包含数据数组的对象

{
  "success": true,
  "message": "Merchant and Shop info for auth user",
  "data": {
    "merchant": {
      "status": "Onboarded",
      "merchant_type": "Medium",
      "merchant_email": "",
      "merchant_logo": "",
      "merchant_name": "Test Merchant",
      "merchant_address": "Dhanmondi 32 Road Bridge, Dhanmondi Bridge, Dhaka 1209, Bangladesh",
      "owner": "ishak",
      "merchant_phone_no": "01521200079",
      "merchant_trade_license_no": "ddww23sa",
      "merchant_trade_license_expiration_date": "2004-06-11T00:00:00.000Z",
      "owner_nid_no": 981567831,
      "owner_nid_image_front": "front-image-url",
      "owner_nid_image_back": "back-image-url",
      "owner_phone_no": "01521200079",
      "owner_email": "owner@email.com",
      "merchant_code": "EM38f2f433",
      "createdAt": "2021-05-02T06:03:00.417Z"
    },
    "shops": {
      "count": 3,
      "shops": [
        {
          "status": "Unapproved",
          "max_allowed_total": 1000000,
          "min_allowed_total": 500,
          "max_order_quantity": 0,
          "max_order_amount": 0,
          "min_order_quantity": 0,
          "min_order_amount": 0,
          "is_delivery_hero_allowed": false,
          "is_cod_allowed": false,
          "is_mother_shop": true,
          "approved": false,
          "allowed_payment_methods": [
            "bkash",
            "sslcommerz_gateway",
            "nagad"
          ],
          "shop_type": "Regular",
          "name": "catalog shop test",
          "address": "merchant address",
          "longitude": 1.55,
          "latitude": 1.06,
          "description": "Long description",
          "logo_image": "logo-image-url",
          "image": "banner-image-url",
          "contact_number": "0123456789",
          "merchant_id": "608e4094d33ca200752ca127",
          "slug": "catalog-shop-test-30ac6c82",
          "createdAt": "2021-05-02T06:18:01.950Z"
        },
        {
          "status": "Unapproved",
          "max_allowed_total": 1000000,
          "min_allowed_total": 500,
          "max_order_quantity": 0,
          "max_order_amount": 0,
          "min_order_quantity": 0,
          "min_order_amount": 0,
          "is_delivery_hero_allowed": false,
          "is_cod_allowed": false,
          "is_mother_shop": true,
          "approved": false,
          "allowed_payment_methods": [
            "bkash",
            "sslcommerz_gateway",
            "nagad"
          ],
          "shop_type": "Regular",
          "name": "catalog shop test 2",
          "address": "merchant address",
          "longitude": 1.55,
          "latitude": 1.06,
          "description": "Long description",
          "logo_image": "logo-image-url",
          "image": "banner-image-url",
          "contact_number": "0123456789",
          "merchant_id": "608e4094d33ca200752ca127",
          "slug": "catalog-shop-test-2-4adb1b9",
          "createdAt": "2021-05-02T06:27:05.286Z"
        },
        {
          "status": "Unapproved",
          "max_allowed_total": 1000000,
          "min_allowed_total": 500,
          "max_order_quantity": 0,
          "max_order_amount": 0,
          "min_order_quantity": 0,
          "min_order_amount": 0,
          "is_delivery_hero_allowed": false,
          "is_cod_allowed": false,
          "is_mother_shop": true,
          "approved": false,
          "allowed_payment_methods": [
            "bkash",
            "sslcommerz_gateway",
            "nagad"
          ],
          "shop_type": "Regular",
          "name": "catalog shop test 3",
          "address": "merchant address test update",
          "longitude": 1.55,
          "latitude": 1.06,
          "description": "description",
          "logo_image": "logo-image-url",
          "image": "banner-image-url",
          "contact_number": "0123456789",
          "merchant_id": "608e4094d33ca200752ca127",
          "slug": "catalog-shop-test-3-1e241f30",
          "createdAt": "2021-05-02T06:33:59.990Z"
        }
      ]
    }
  }
}
现在我想列出每个
商店
数组中的所有
slug
,其中
是“母亲商店”:是的,
我想我需要在JS中执行一些数组过滤操作,但我无法找到解决方案。我需要创建一个包含所有
slug
的数组,其中
“is_mother_shop”:true,
用于此响应数据中所有登记的
商店
。我不确定什么应该是它的良好实现。

您可以使用

slugs = response.data?.shops?.shops
    ?.filter((p) => p.is_mother_shop)
    .map((p) => p.slug);

工作示例:

您可以分享您的尝试吗?过滤数组并获取过滤项的
slug
属性。您实际上不需要使用
map
进行可选链接。如果
filter
存在
map
也会存在。编辑答案
data.data.shops.shops.filter(el => el.is_mother_shop).map(el => el.slug)