0

I need help with javascript code, i want to display the:

AK-47 | Aquamarine Revenge (Battle-Scarred)

i tried just copy pasting it like: "value.AK-47 | Aquamarine Revenge (Battle-Scarred)"

but it didnt work

  1. How do i put it into the " value. " ?
  2. i would like to display the "24_hours"-"average" but i don't know how to do it.
  3. If there are numbers how do i select them?

Javascript:

$.ajax({
    url: 'download.json',
    dataType: 'json',
    type: 'get',
    cache: false,
    success: function(data){
        $(data.items_list).each(function(index, value) {
            console.log(value. )));
        });
    }
});

JSON File:

{
    "currency": "USD",
    "items_list": {
        "AK-47 | Aquamarine Revenge (Battle-Scarred)": {
            "classid": "1759174527",
            "exterior": "Battle-Scarred",
            "first_sale_date": "1432764000",
            "gun_type": "AK-47",
            "icon_url": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpot7HxfDhjxszJemkV09-5gZKKkPLLMrfFqWNU6dNoxL3H94qm3Ffm_RE6amn2ctWXdlI2ZwqB-FG_w-7s0ZK-7cjLzyE37HI8pSGKrIDGOAI",
            "icon_url_large": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpot7HxfDhjxszJemkV09-5gZKKkPLLMrfFqWNU6dNoteXA54vwxgCyqRVvZzrxItTDewY7NwvS_gW2x7y-h5a9vp3KnXZh63Ug4yyJyUepwUYbPABm4j8",
            "marketable": 1,
            "name": "AK-47 | Aquamarine Revenge (Battle-Scarred)",
            "price": {
                "24_hours": {
                    "average": 18.54,
                    "highest_price": 28.4,
                    "lowest_price": 15.85,
                    "median": 18.22,
                    "sold": "13",
                    "standard_deviation": "19.82"
                },
                "30_days": {
                    "average": 15.32,
                    "highest_price": 28.4,
                    "lowest_price": 8.31,
                    "median": 15.32,
                    "sold": "1611",
                    "standard_deviation": "8.96"
                },
                "7_days": {
                    "average": 16.5,
                    "highest_price": 28.4,
                    "lowest_price": 14.13,
                    "median": 16.4,
                    "sold": "400",
                    "standard_deviation": "9.18"
                },
                "all_time": {
                    "average": 12.42,
                    "highest_price": 32.68,
                    "lowest_price": 6.62,
                    "median": 14.25,
                    "sold": "170751",
                    "standard_deviation": "27.86"
                },
            },
        },
        
    }
}
Temi1337
  • 21
  • 6
  • 1
    Does this answer your question? [How can I access and process nested objects, arrays or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – Ivar Dec 29 '20 at 23:13
  • 1
    Use [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#Bracket_notation). – Ivar Dec 29 '20 at 23:14
  • [Duplicate](https://google.com/search?q=site%3Astackoverflow.com+js+access+property+with+special+symbols) of [How to access object properties containing special characters?](https://stackoverflow.com/q/12953704/4642212). – Sebastian Simon Dec 29 '20 at 23:14
  • When you have special characters, such as `+ < > space - / *`, etc., you need to use string indexing. So you would say `value["AK-47 | Aquamarine Revenge (Battle-Scarred)"]`. For keys that include numbers, you would also use string indexing. – Samathingamajig Dec 29 '20 at 23:16
  • @Samathingamajig _“For keys that include numbers”_ — Not necessarily. Bracket notation is needed for keys that _start_ with digits, because those are not valid identifiers. – Sebastian Simon Dec 29 '20 at 23:34

1 Answers1

-1

Your question is quite confusing. Do you mean you want to fetch the string value from the JSON and display it through JQuery Foreach loop. 'value' in here is the parameter which will hold the value(not the key) of the object from the first parameter of each() function.

$.ajax({
url: 'download.json',
dataType: 'json',
type: 'get',
cache: false,
success: function(data){
    //Try it like this
    $.each(data['items_list'], function(index, value) {
        console.log(index)));
        console.log(value['name'])));
    });
}

});

ZHANG WEI
  • 39
  • 3