It's just two cycles we've built. https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/for...in let data = getData();
let items = data.items_list
let arr = [];
for (let key in items) {
let name = items[key].name;
let price_obj = items[key].price;
for (let interval in price_obj) {
let lowest = price_obj[interval].lowest_price;
arr.push( name + " && " + interval + " && " + lowest );
}
}
console.log(arr);
/***/
function getData() {
return {
success: true,
currency: "USD",
timestamp: 1598651972,
items_list: {
"3 rd Commando Company | KSK": {
name: "3rd Commando Company | KSK",
price: {
"24 _hours": {
average: 2.76,
median: 2.81,
sold: "517",
standard_deviation: "3.45",
lowest_price: 2.55,
highest_price: 2.89
},
"7 _days": {
average: 2.79,
median: 2.79,
sold: "3095",
standard_deviation: "2.99",
lowest_price: 2.55,
highest_price: 2.92
},
"30 _days": {
average: 2.84,
median: 2.86,
sold: "13238",
standard_deviation: "3.77",
lowest_price: 2.55,
highest_price: 3.06
},
all_time: {
average: 3.84,
median: 2.84,
sold: "256893",
standard_deviation: "30.03",
lowest_price: 2.01,
highest_price: 12.78
}
},
first_sale_date: "1574118000"
},
"AK - 47 | Aquamarine Revenge(Battle - Scarred)": {
name: "AK-47 | Aquamarine Revenge (Battle-Scarred)",
price: {
"24 _hours": {
average: 17.09,
median: 17.19,
sold: "42",
standard_deviation: "5.57",
lowest_price: 14.76,
highest_price: 18.5
},
"7 _days": {
average: 17.74,
median: 17.68,
sold: "293",
standard_deviation: "4.7",
lowest_price: 14.26,
highest_price: 19.33
},
"30 _days": {
average: 18.44,
median: 18.39,
sold: "1124",
standard_deviation: "5.49",
lowest_price: 14.26,
highest_price: 20.71
},
"all_time": {
average: 12.69,
median: 14.82,
sold: "165598",
standard_deviation: "31.33",
lowest_price: 6.83,
highest_price: 33.7
}
},
first_sale_date: "1432764000"
}
}
}
}Or another way. https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/for...of let data = getData();
let arr = [];
for ( let item of Object.values(data.items_list) ) {
let name = item.name;
let prices = item.price;
for ( let [interval, price_obj] of Object.entries(prices) ) {
let lowest = price_obj.lowest_price;
arr.push( name + " && " + interval + " && " + lowest );
}
}
console.log(arr);
// *google → Object.values, Object.entries, Деструктурирующее присваивание
/***/
function getData() {
return {
success: true,
currency: "USD",
timestamp: 1598651972,
items_list: {
"3 rd Commando Company | KSK": {
name: "3rd Commando Company | KSK",
price: {
"24 _hours": {
average: 2.76,
median: 2.81,
sold: "517",
standard_deviation: "3.45",
lowest_price: 2.55,
highest_price: 2.89
},
"7 _days": {
average: 2.79,
median: 2.79,
sold: "3095",
standard_deviation: "2.99",
lowest_price: 2.55,
highest_price: 2.92
},
"30 _days": {
average: 2.84,
median: 2.86,
sold: "13238",
standard_deviation: "3.77",
lowest_price: 2.55,
highest_price: 3.06
},
all_time: {
average: 3.84,
median: 2.84,
sold: "256893",
standard_deviation: "30.03",
lowest_price: 2.01,
highest_price: 12.78
}
},
first_sale_date: "1574118000"
},
"AK - 47 | Aquamarine Revenge(Battle - Scarred)": {
name: "AK-47 | Aquamarine Revenge (Battle-Scarred)",
price: {
"24 _hours": {
average: 17.09,
median: 17.19,
sold: "42",
standard_deviation: "5.57",
lowest_price: 14.76,
highest_price: 18.5
},
"7 _days": {
average: 17.74,
median: 17.68,
sold: "293",
standard_deviation: "4.7",
lowest_price: 14.26,
highest_price: 19.33
},
"30 _days": {
average: 18.44,
median: 18.39,
sold: "1124",
standard_deviation: "5.49",
lowest_price: 14.26,
highest_price: 20.71
},
"all_time": {
average: 12.69,
median: 14.82,
sold: "165598",
standard_deviation: "31.33",
lowest_price: 6.83,
highest_price: 33.7
}
},
first_sale_date: "1432764000"
}
}
}
}P.s. You can still write through regular expressions and pretend you're a hacker:let x = data().match(/name:\s?.?,\sprice:\s*{(\s*.?{(?:.|\s)?},?)+/g)
.map((e,i) => (i = e.replace(/(name:\s?.?,\sprice:\s*{)/g, ""),
i.match(/\s*(.?):\s{/g)
.map((v,i) => e.match(/(?<=name:\s?)"([^"]+)/)[1] + " && " +
v.match(/\s*(.?):\s{/)[1] + " && " +
e.match(/(?<=lowest_price:\s+)\d+(?:.\d+)?/g)[i]) )).flat();
console.log(x);
function data() {
return `{
success: true,
currency: "USD",
timestamp: 1598651972
items_list: {
3rd Commando Company | KSK: {
name: "3rd Commando Company | KSK",
price: {
24_hours: {
average: 2.76,
median: 2.81,
sold: "517",
standard_deviation: "3.45",
lowest_price: 2.55,
highest_price: 2.89
},
7_days: {
average: 2.79,
median: 2.79,
sold: "3095",
standard_deviation: "2.99",
lowest_price: 2.55,
highest_price: 2.92
},
30_days: {
average: 2.84,
median: 2.86,
sold: "13238",
standard_deviation: "3.77",
lowest_price: 2.55,
highest_price: 3.06
},
all_time: {
average: 3.84,
median: 2.84,
sold: "256893",
standard_deviation: "30.03",
lowest_price: 2.01,
highest_price: 12.78
}
},
first_sale_date: "1574118000"
},
AK-47 | Aquamarine Revenge (Battle-Scarred): {
name: "AK-47 | Aquamarine Revenge (Battle-Scarred)",
price: {
24_hours: {
average: 17.09,
median: 17.19,
sold: "42",
standard_deviation: "5.57",
lowest_price: 14.76,
highest_price: 18.5
},
7_days: {
average: 17.74,
median: 17.68,
sold: "293",
standard_deviation: "4.7",
lowest_price: 14.26,
highest_price: 19.33
},
30_days: {
average: 18.44,
median: 18.39,
sold: "1124",
standard_deviation: "5.49",
lowest_price: 14.26,
highest_price: 20.71
},
all_time: {
average: 12.69,
median: 14.82,
sold: "165598",
standard_deviation: "31.33",
lowest_price: 6.83,
highest_price: 33.7
}
},
first_sale_date: "1432764000"
}`;
}Alas, that's impossible to understand.
If there's anything you want to do, I'm referring to nucleus. https://regex101.com/