Related
I have searched a lot regarding filter of product data using checkbox but couldn't able to find the right answer for my issue.
Problem: I'm making a product filter page using checkbox in react but could not found the proper way to filter the true value of object key.
ie. I have to only filter object key value === true. Below array object is after checkbox selection before the selection it will be falsy value.
const category = [
{
"type":"Color",
"options":[
{
"key":"Red",
"value":true
},
{
"key":"Blue",
"value":false
},
{
"key":"Green",
"value":true
}
]
},
{
"type":"Gender",
"options":[
{
"key":"Men",
"value":true
},
{
"key":"Women",
"value":false
}
]
},
{
"type":"Price",
"options":[
{
"key":"0 - Rs. 250",
"from":0,
"to":250,
"value":false
},
{
"key":"Rs. 251 - 450",
"from":251,
"to":450,
"value":true
},
{
"key":"Rs. 451 & above",
"from":451,
"to":"Number.MAX_VALUE",
"value":false
}
]
},
{
"type":"Type",
"options":[
{
"key":"Polo",
"value":false
},
{
"key":"Hoodie",
"value":false
},
{
"key":"Basic",
"value":true
}
]
}
]
const productData = [
{
"id": 1,
"name": "Black Polo",
"type": "Polo",
"price": 250,
"currency": "INR",
"color": "Black",
"gender": "Men",
"quantity": 3
},
{
"id": 2,
"name": "Blue Polo",
"type": "Polo",
"price": 350,
"currency": "INR",
"color": "Blue",
"gender": "Women",
"quantity": 3
},
{
"id": 3,
"name": "Pink Polo",
"type": "Polo",
"price": 350,
"currency": "INR",
"color": "Pink",
"gender": "Women",
"quantity": 6
},
{
"id": 4,
"name": "Black Hoodie",
"type": "Hoodie",
"price": 500,
"currency": "INR",
"color": "Black",
"gender": "Men",
"quantity": 2
},
{
"id": 5,
"name": "Green Polo",
"type": "Polo",
"price": 250,
"currency": "INR",
"color": "Green",
"gender": "Men",
"quantity": 1
},
{
"id": 6,
"name": "Green Polo",
"type": "Polo",
"price": 350,
"currency": "INR",
"color": "Green",
"gender": "Women",
"quantity": 1
},
{
"id": 7,
"name": "Blue Hoodie",
"type": "Hoodie",
"price": 500,
"currency": "INR",
"color": "Blue",
"gender": "Women",
"quantity": 2
},
{
"id": 8,
"name": "Black Hoodie",
"type": "Hoodie",
"price": 500,
"currency": "INR",
"color": "Black",
"gender": "Women",
"quantity": 5
}]
Now,I need filtered product data from the above category data and product-data.
Here's my Codesandbox link for this.
I have used Angular as programming language for my project and i am a beginner. But i am stuck at the point where i have to generate PDF of my JSON response.
Looked at the documentation of PDFMAKE to achieve the same, but couldnot figure out how to implement it and come out with the output as shown in following image.
Output Structure Image
The JSON response is as follows:
{
"statusCode": true,
"data": [
{
"partyId": 1,
"partyIdDisp": "1/PA/2077",
"createdDate": "2077/05/03",
"partyName": "Roshan Basnet",
"contactNumber": 9841040791,
"companyName": "Butwal Poultry",
"panNumber": 321654,
"address": "Butwal, Nepal",
"saleDetails": [
{
"_id": "5f5b234cbac67e377c2a700f",
"saleId": 1,
"saleIdDisp": "1/S/2077",
"createdDate": "2077/05/26",
"saleType": "Credit",
"customerId": 1,
"customerName": "Roshan Basnet",
"contactNumber": 9841040791,
"billingName": "Butwal Poultry",
"billingAddress": "Butwal, Nepal",
"billDate": "2077/05/26",
"itemDetails": [
{
"_id": "5f5b234cbac67e377c2a7010",
"itemId": 1,
"itemName": "Chicken",
"quantity": 10,
"unit": "KG",
"piece": 5,
"receiptNo": null,
"billNo": 366,
"unitPrice": 310,
"itemAmount": 3100
}
],
"totalQuantity": 10,
"paymentMethod": "Cash",
"subTotal": 3100,
"amountInWords": "three thousand one hundred only",
"outstandingBalance": 0,
"receivedAmount": 3000,
"balanceAmount": 100,
"__v": 0
},
{
"_id": "5f5b2375bac67e377c2a7012",
"saleId": 2,
"saleIdDisp": "2/S/2077",
"createdDate": "2077/05/26",
"saleType": "Credit",
"customerId": 1,
"customerName": "Roshan Basnet",
"contactNumber": 9841040791,
"billingName": "Butwal Poultry",
"billingAddress": "Butwal, Nepal",
"billDate": "2077/05/26",
"itemDetails": [
{
"_id": "5f5b2375bac67e377c2a7013",
"itemId": 2,
"itemName": "Mutton",
"quantity": 5,
"unit": "KG",
"piece": 0,
"receiptNo": null,
"billNo": 266,
"unitPrice": 1200,
"itemAmount": 6000
},
{
"_id": "5f5b2375bac67e377c2a7014",
"itemId": 3,
"itemName": "Eggs",
"quantity": 10,
"unit": "Crate",
"piece": 0,
"receiptNo": null,
"billNo": 366,
"unitPrice": 390,
"itemAmount": 3900
}
],
"totalQuantity": 15,
"paymentMethod": "Cash",
"subTotal": 10000,
"amountInWords": "ten thousand only",
"outstandingBalance": 100,
"receivedAmount": 5000,
"balanceAmount": 5000,
"__v": 0
}
]
}
]
}
A code snippet how to generate a pdf output as per the structure in the image would be helpful.
This question already has answers here:
How to find object in array by property in javascript?
(3 answers)
Closed 2 years ago.
I have the Basic Recipe array with the details objects:
I want to be able to update the value of specific item inside the details i.e item with ID 5f3aadd5d756e9341ef74e2b
{
"brandName": "Piatto",
"_id": "5f3aadd5d756e9341ef74e29",
"name": "Test",
"rate": 89,
"baseQuantity": 1000,
"baseUnit": "gm",
"details": [
{
"_id": "5f3aadd5d756e9341ef74e2b",
"rawMaterial": "Egg white 1",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 12,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "ml",
"displayRateUnit": "1/2 lit."
},
{
"_id": "5f3aadd5d756e9341ef74e2a",
"rawMaterial": "Egg white 2",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 14,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "gm",
"displayRateUnit": "1/2 lit."
}
],
"__v": 0
}
Please help!
Try this.
var data = {
"brandName": "Piatto",
"_id": "5f3aadd5d756e9341ef74e29",
"name": "Test",
"rate": 89,
"baseQuantity": 1000,
"baseUnit": "gm",
"details": [{
"_id": "5f3aadd5d756e9341ef74e2b",
"rawMaterial": "Egg white 1",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 12,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "ml",
"displayRateUnit": "1/2 lit."
},
{
"_id": "5f3aadd5d756e9341ef74e2a",
"rawMaterial": "Egg white 2",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 14,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "gm",
"displayRateUnit": "1/2 lit."
}
],
"__v": 0
};
var idToBeUpdate = '5f3aadd5d756e9341ef74e2b'
data.details.forEach(x => {
if (x._id === idToBeUpdate) {
x.rawMaterial = "Egg white 3 <updated>"
}
});
console.log(data);
Ciao, you could use a filter function to get element you want to update based on _id, and then modify it like:
let input = {
"brandName": "Piatto",
"_id": "5f3aadd5d756e9341ef74e29",
"name": "Test",
"rate": 89,
"baseQuantity": 1000,
"baseUnit": "gm",
"details": [
{
"_id": "5f3aadd5d756e9341ef74e2b",
"rawMaterial": "Egg white 1",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 12,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "ml",
"displayRateUnit": "1/2 lit."
},
{
"_id": "5f3aadd5d756e9341ef74e2a",
"rawMaterial": "Egg white 2",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 14,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "gm",
"displayRateUnit": "1/2 lit."
}
],
"__v": 0
}
let elementToUpdate = input.details.filter(el => el._id === "5f3aadd5d756e9341ef74e2b")[0]
// this is the element filtered by _id
console.log(elementToUpdate)
//lets say you want to update rawMaterial
elementToUpdate.rawMaterial += ", Egg black 2"
console.log(elementToUpdate)
// this is the input object modified
console.log(input)
I am looking to find a way to compare and combine two multidimensinal array of objects based on course values. I can make it work using the filter method for the top level, but not sure how to make sure that all levelwithskills are deeply merged. Here is an example:
var array1 = [
{
"course": "Javascript and protractor",
"description": "this is test course",
"levelwithskills": [
{
"name": "Beginner",
"skills": [
{
"duration": 45,
"name": "HTML/CSS/JS",
"price": 75
},
{
"duration": 45,
"name": "Data And Flows",
"price": 75
},
{
"duration": 45,
"name": "Functions And Objects",
"price": 75
},
{
"duration": 45,
"name": "Protractor Project",
"price": 75
}
]
},
{
"name": "Improver",
"skills": [
{
"duration": 45,
"name": "Jasmine",
"price": 90
},
{
"duration": 45,
"name": "Protractor Methods",
"price": 90
},
{
"duration": 45,
"name": "Non Angular App Testing",
"price": 90
},
{
"duration": 45,
"name": "Reports",
"price": 90
}
]
},
{
"name": "Intermediate",
"skills": [
{
"duration": 45,
"name": "Crossbrowser Config",
"price": 100
},
{
"duration": 45,
"name": "Data-Driven",
"price": 100
},
{
"duration": 45,
"name": "Gulp-Integration",
"price": 100
},
{
"duration": 45,
"name": "User Stories To Test",
"price": 100
}
]
}
],
"s3key": "javascsipt.png"
},
{
"course": "Java and BDD",
"id": "564e0758-803f-11e9-ba30-01cdbe15a808",
"levelwithskills": [
{
"name": "Beginner",
"skills": [
{
"duration": 45,
"name": "HTML/CSS/JS",
"price": 1
},
{
"duration": 45,
"name": "Data and flows",
"price": 1
},
{
"duration": 45,
"name": "OOP",
"price": 1
},
{
"duration": 45,
"name": "Libraries",
"price": 1
}
]
},
{
"name": "Improver",
"skills": [
{
"duration": 45,
"name": "Selenium Webdriver",
"price": 90
},
{
"duration": 45,
"name": "Junit",
"price": 90
},
{
"duration": 45,
"name": "Saucelabs",
"price": 90
},
{
"duration": 45,
"name": "User Stories To Test",
"price": 90
}
]
},
{
"name": "Intermediate",
"skills": [
{
"duration": 45,
"name": "Most Used Methods",
"price": 100
},
{
"duration": 45,
"name": "Git",
"price": 100
},
{
"duration": 45,
"name": "Gherkin",
"price": 100
},
{
"duration": 45,
"name": "Cucumber",
"price": 100
}
]
},
{
"name": "Semi-Advance",
"skills": [
{
"duration": 45,
"name": "Maven",
"price": 110
},
{
"duration": 45,
"name": "Cucumber Data-driven",
"price": 11000
},
{
"duration": 45,
"name": "Jenkins",
"price": 110
},
{
"duration": 45,
"name": "Pipeline",
"price": 110
}
]
},
{
"name": "Advance",
"skills": [
{
"duration": 45,
"name": "Page Object Model",
"price": 120
},
{
"duration": 45,
"name": "Advanced Methods",
"price": 120
},
{
"duration": 45,
"name": "Advanced Logic",
"price": 120
},
{
"duration": 45,
"name": "Your Own Framework",
"price": 120
}
]
},
{
"name": "Professional",
"skills": [
{
"duration": 45,
"name": "Serenit Framework p1",
"price": 130
},
{
"duration": 45,
"name": "Serenit Framework p2",
"price": 130
},
{
"duration": 45,
"name": "Serenit Framework p3",
"price": 130
},
{
"duration": 45,
"name": "Serenit Framework p4",
"price": 130
}
]
}
],
"passion": "Tester",
"s3key": "java.png",
}
];
var array2 = [
{
"course": "Javascript and protractor",
"levelwithskills": [
{
"name": "Beginner",
"skills": [
{
"name": "HTML/CSS/JS"
}
]
}
]
}
,
{
"course": "Java and BDD",
"levelwithskills": [
{
"name": "Beginner",
"skills": [
{
"name": "HTML/CSS/JS"
}
]
}
]
}
];
const sameData = array1.map(
obj =>
array2.map(obj2 => {
if (obj.course === obj2.course) {
return {
...obj,
levelwithskills: obj.levelwithskills.map(
xlvl =>
obj2.levelwithskills.map(ylvl => {
if (xlvl.name === ylvl.name) {
return {
...xlvl,
skills: xlvl.skills.map(
xskill =>
ylvl.skills.map(yskill => {
if (xskill.name === yskill.name) {
return {
...xskill,
selected: true
};
}
return xskill;
})[0]
)
};
}
return xlvl;
})[0]
)
};
}
})[0]
);
console.log(sameData);
I am looking to take something like that and merge it like:
[
{
"course": "Javascript and protractor",
"description": "this is test course",
"levelwithskills": [
{
"name": "Beginner",
"skills": [
{
"duration": 45,
"name": "HTML/CSS/JS",
"price": 75,
"selected": true
},
{
"duration": 45,
"name": "Data And Flows",
"price": 75
},
{
"duration": 45,
"name": "Functions And Objects",
"price": 75
},
{
"duration": 45,
"name": "Protractor Project",
"price": 75
}
]
},
{
"name": "Improver",
"skills": [
{
"duration": 45,
"name": "Jasmine",
"price": 90
},
{
"duration": 45,
"name": "Protractor Methods",
"price": 90
},
{
"duration": 45,
"name": "Non Angular App Testing",
"price": 90
},
{
"duration": 45,
"name": "Reports",
"price": 90
}
]
},
{
"name": "Intermediate",
"skills": [
{
"duration": 45,
"name": "Crossbrowser Config",
"price": 100
},
{
"duration": 45,
"name": "Data-Driven",
"price": 100
},
{
"duration": 45,
"name": "Gulp-Integration",
"price": 100
},
{
"duration": 45,
"name": "User Stories To Test",
"price": 100
}
]
}
],
"s3key": "javascsipt.png"
},
{
"course": "Java and BDD",
"id": "564e0758-803f-11e9-ba30-01cdbe15a808",
"levelwithskills": [
{
"name": "Beginner",
"skills": [
{
"duration": 45,
"name": "HTML/CSS/JS",
"price": 1
"selected": true
},
{
"duration": 45,
"name": "Data and flows",
"price": 1
},
{
"duration": 45,
"name": "OOP",
"price": 1
},
{
"duration": 45,
"name": "Libraries",
"price": 1
}
]
},
{
"name": "Improver",
"skills": [
{
"duration": 45,
"name": "Selenium Webdriver",
"price": 90
},
{
"duration": 45,
"name": "Junit",
"price": 90
},
{
"duration": 45,
"name": "Saucelabs",
"price": 90
},
{
"duration": 45,
"name": "User Stories To Test",
"price": 90
}
]
},
{
"name": "Intermediate",
"skills": [
{
"duration": 45,
"name": "Most Used Methods",
"price": 100
},
{
"duration": 45,
"name": "Git",
"price": 100
},
{
"duration": 45,
"name": "Gherkin",
"price": 100
},
{
"duration": 45,
"name": "Cucumber",
"price": 100
}
]
},
{
"name": "Semi-Advance",
"skills": [
{
"duration": 45,
"name": "Maven",
"price": 110
},
{
"duration": 45,
"name": "Cucumber Data-driven",
"price": 11000
},
{
"duration": 45,
"name": "Jenkins",
"price": 110
},
{
"duration": 45,
"name": "Pipeline",
"price": 110
}
]
},
{
"name": "Advance",
"skills": [
{
"duration": 45,
"name": "Page Object Model",
"price": 120
},
{
"duration": 45,
"name": "Advanced Methods",
"price": 120
},
{
"duration": 45,
"name": "Advanced Logic",
"price": 120
},
{
"duration": 45,
"name": "Your Own Framework",
"price": 120
}
]
},
{
"name": "Professional",
"skills": [
{
"duration": 45,
"name": "Serenit Framework p1",
"price": 130
},
{
"duration": 45,
"name": "Serenit Framework p2",
"price": 130
},
{
"duration": 45,
"name": "Serenit Framework p3",
"price": 130
},
{
"duration": 45,
"name": "Serenit Framework p4",
"price": 130
}
]
}
],
"passion": "Tester",
"s3key": "java.png",
}
]
Deep merge objects/arrays:
Taken from drupal - drupal_array_merge_deep_array and re-written in JS)
function array_merge_deep_array(arrays) {
let result = [];
for (let i in arrays){
for (let key in arrays[i]){
const value = arrays[i][key];
// Renumber integer keys
if (typeof(key) === 'number') {
result.push(value);
}
else if (result[key] && typeof(result[key]) === 'object' && typeof(value) === 'object') {
result[key] = array_merge_deep_array([
result[key],
value,
]);
}
else {
result[key] = value;
}
}
}
return result;
}
I am trying to output parts of the json below:
How would I output the value pint from beer.name.568.name ?
{
"beer": {
"name": "Beer or cider",
"sizes": {
"568": {
"name": "Pint",
"size": 0.568,
"id": "pint",
"max": 10,
"icon": "beer_pint"
},
"440": {
"name": "Can",
"size": 0.44,
"id": "can",
"max": 10,
"icon": "beer_can"
},
"330": {
"name": "Bottle",
"size": "0.33",
"id": "bottle",
"max": "10",
"icon": "beer_bottle_330"
},
"275": {
"name": "Small bottle",
"size": 0.275,
"id": "smallBottle",
"max": 10,
"icon": "beer_bottle_275"
}
},
"strength": [4, 4.5, 5, 6, 7, 8, 9]
},
"wine": {
"name": "Wine or champagne",
"sizes": {
"125": {
"name": "Small glass",
"size": 0.125,
"id": "small",
"max": 10,
"icon": "wine_small_glass"
},
"175": {
"name": "Standard glass",
"size": 0.175,
"id": "std",
"max": 10,
"icon": "wine_standard_glass"
},
"250": {
"name": "Large glass",
"size": 0.25,
"id": "large",
"max": 10,
"icon": "wine_large_glass"
},
"1000": {
"name": "Bottle",
"size": 1,
"id": "bottle",
"max": 10,
"icon": "wine_bottle"
}
},
"strength": [9, 10, 10.5, 11, 11.5, 12, 13, 14, 15, 16, 17]
},
"spirits": {
"name": "Spirits or shots",
"sizes": {
"25": {
"name": "Single",
"size": 0.025,
"id": "single",
"max": 10,
"icon": "spirit_single"
},
"35": {
"name": "Large single",
"size": 0.035,
"id": "lgSingle",
"max": 10,
"icon": "spirit_large_single"
},
"50": {
"name": "Double",
"size": 0.05,
"id": "double",
"max": 10,
"icon": "spirit_double"
},
"70": {
"name": "Large double",
"size": 0.07,
"id": "lgDouble",
"max": 10,
"icon": "spirit_large_double"
},
"700": {
"name": "Bottle",
"size": 0.7,
"id": "bottle700",
"max": 3,
"icon": "spirit_bottles"
},
"1000": {
"name": "Bottle",
"size": 1,
"id": "bottle",
"max": 3,
"icon": "spirit_bottles"
}
},
"strength": [37, 40]
},
"alcopop": {
"name": "Alcopop",
"sizes": {
"275": {
"name": "Small bottle",
"size": 0.275,
"id": "small",
"max": 10,
"icon": "alcopops_small_bottle"
},
"330": {
"name": "Standard bottle",
"size": 0.33,
"id": "std",
"max": 10,
"icon": "alcopops_standard_bottle"
},
"750": {
"name": "Large bottle",
"size": 0.75,
"id": "large",
"max": 10,
"icon": "alcopops_large_bottle"
}
},
"strength": [5, 5.5]
}
}
Obviously this approach may have many drawbacks as the loop can go infinite in some situations, but, if you know that your structure is "stable", this can simulate a search in some dynamic json schema, when you know a key and want to get a property value.
var data = {
"beer": {
"name": "Beer or cider",
"sizes": {
"568": {
"name": "Pint",
"size": 0.568,
"id": "pint",
"max": 10,
"icon": "beer_pint"
},
"440": {
"name": "Can",
"size": 0.44,
"id": "can",
"max": 10,
"icon": "beer_can"
},
"330": {
"name": "Bottle",
"size": "0.33",
"id": "bottle",
"max": "10",
"icon": "beer_bottle_330"
},
"275": {
"name": "Small bottle",
"size": 0.275,
"id": "smallBottle",
"max": 10,
"icon": "beer_bottle_275"
}
},
"strength": [4, 4.5, 5, 6, 7, 8, 9]
},
"wine": {
"name": "Wine or champagne",
"sizes": {
"125": {
"name": "Small glass",
"size": 0.125,
"id": "small",
"max": 10,
"icon": "wine_small_glass"
},
"175": {
"name": "Standard glass",
"size": 0.175,
"id": "std",
"max": 10,
"icon": "wine_standard_glass"
},
"250": {
"name": "Large glass",
"size": 0.25,
"id": "large",
"max": 10,
"icon": "wine_large_glass"
},
"1000": {
"name": "Bottle",
"size": 1,
"id": "bottle",
"max": 10,
"icon": "wine_bottle"
}
},
"strength": [9, 10, 10.5, 11, 11.5, 12, 13, 14, 15, 16, 17]
},
"spirits": {
"name": "Spirits or shots",
"sizes": {
"25": {
"name": "Single",
"size": 0.025,
"id": "single",
"max": 10,
"icon": "spirit_single"
},
"35": {
"name": "Large single",
"size": 0.035,
"id": "lgSingle",
"max": 10,
"icon": "spirit_large_single"
},
"50": {
"name": "Double",
"size": 0.05,
"id": "double",
"max": 10,
"icon": "spirit_double"
},
"70": {
"name": "Large double",
"size": 0.07,
"id": "lgDouble",
"max": 10,
"icon": "spirit_large_double"
},
"700": {
"name": "Bottle",
"size": 0.7,
"id": "bottle700",
"max": 3,
"icon": "spirit_bottles"
},
"1000": {
"name": "Bottle",
"size": 1,
"id": "bottle",
"max": 3,
"icon": "spirit_bottles"
}
},
"strength": [37, 40]
},
"alcopop": {
"name": "Alcopop",
"sizes": {
"275": {
"name": "Small bottle",
"size": 0.275,
"id": "small",
"max": 10,
"icon": "alcopops_small_bottle"
},
"330": {
"name": "Standard bottle",
"size": 0.33,
"id": "std",
"max": 10,
"icon": "alcopops_standard_bottle"
},
"750": {
"name": "Large bottle",
"size": 0.75,
"id": "large",
"max": 10,
"icon": "alcopops_large_bottle"
}
},
"strength": [5, 5.5]
}
};
function findPropertyValueForKey(prev, key, property, data) {
if (typeof data != "object") return;
var keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
if (keys[i] == key) {
prev.push(data[key][property]);
} else {
findPropertyValueForKey(prev, key, property, data[keys[i]]);
}
}
};
var results = [];
findPropertyValueForKey(results, "568", "name", data);
console.log(results);
var beer = {
"sizes": {
"568": {
"name": "Pint"
}
}
}
console.log(beer.sizes[568].name); // "Pint"
console.log(beer['sizes'][568]['name']); // "Pint"