0

Hi I have an array (see below for the first part of the array) and I can get the name using the code (my code is in a loop to get all names from the array)

jsonFabric.values[i].name

which gives me "3002-023"

How do I get the labels name?

which would give me "Fabric".

I have tried many variations including

jsonFabric.values[i].labels['name']

but they do not get "Fabric"

{
    "totalRows": 151,
    "values": [
        {
            "width": 1338,
            "height": 2397,
            "isNew": true,
            "defaultScene": null,
            "displayUrl": "https://example.com/designs-324/3002%20023_small.png?1=1&width=500&Cache=Default&height=500&p.dc=1&mode=max&format=jpg&timestamp=636244299470877669",
            "renderUrl": "https://example.com/designs-324/3002%20023.tif?1=1&width=-1&Cache=Default&p.dc=1&mode=max&format=jpg&timestamp=636244299470877669",
            "designOptions": {
                "repeat": true,
                "width": 114,
                "height": 203,
                "gloss": 0,
                "contrast": 0,
                "dropX": 0,
                "dropY": 0,
                "placingPointX": 0.5,
                "placingPointY": 0.5,
                "flip": false,
                "rotation": 0
            },
            "id": 324,
            "name": "3002-023",
            "properties": [],
            "propertiesPerLabel": [],
            "labels": [
                {
                    "id": 1,
                    "parentId": 0,
                    "name": "Fabric",
                    "path": []
                }
            ],
            "description": null,
            "createDate": "2017-03-06T20:45:47.0877669",
            "lastSaveDate": "2017-03-09T13:49:38.5256163",
            "attachments": [],
            "storageName": "3002 023.tif",
            "storagePath": "designs-324/3002 023.tif",
            "relations": {
                "direct": []
            },
            "referenceId": "3002-023.tif"
        }, 

and so on.....

        {
            "width": 1354,
            "height": 1870,
            "isNew": true,
1
  • labels is an array. You need to provide an index and then access using the 'name' parameter. i.e. jsonFabric.values[i].labels[0].name Commented May 1, 2017 at 21:23

2 Answers 2

2

labels represents an array. You need to access the first object of this array to print its name:

jsonFabric.values[i].labels[0].name
Sign up to request clarification or add additional context in comments.

Comments

1

labels is an array, so you need to either select the first element(if there is only one) or loop through to grab the name from each.

let obj = {
  "totalRows": 151,
  "values": [{
    "width": 1338,
    "height": 2397,
    "isNew": true,
    "defaultScene": null,
    "displayUrl": "https://example.com/designs-324/3002%20023_small.png?1=1&width=500&Cache=Default&height=500&p.dc=1&mode=max&format=jpg&timestamp=636244299470877669",
    "renderUrl": "https://example.com/designs-324/3002%20023.tif?1=1&width=-1&Cache=Default&p.dc=1&mode=max&format=jpg&timestamp=636244299470877669",
    "designOptions": {
      "repeat": true,
      "width": 114,
      "height": 203,
      "gloss": 0,
      "contrast": 0,
      "dropX": 0,
      "dropY": 0,
      "placingPointX": 0.5,
      "placingPointY": 0.5,
      "flip": false,
      "rotation": 0
    },
    "id": 324,
    "name": "3002-023",
    "properties": [],
    "propertiesPerLabel": [],
    "labels": [{
      "id": 1,
      "parentId": 0,
      "name": "Fabric",
      "path": []
    }],
    "description": null,
    "createDate": "2017-03-06T20:45:47.0877669",
    "lastSaveDate": "2017-03-09T13:49:38.5256163",
    "attachments": [],
    "storageName": "3002 023.tif",
    "storagePath": "designs-324/3002 023.tif",
    "relations": {
      "direct": []
    },
    "referenceId": "3002-023.tif"
  }]
}

console.log(obj.values[0].labels[0].name)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.