Sign in
Log inSign up

How do I access this JSON values?

Default profile photo
Anonymous
·Dec 10, 2019

I am working on an Income tax calculator in JS based on Indian tax slabs.

I am new to JSON and JS. Can anyone tell me how can I access values from this and compare it with user input and do the calculation?

Conditions:

#1. If User chose 2019_20 as year, it should fetch value from 2019_20.

#2. After that user choose the age and so, if 2019_20 is selected, and age 60 or below is selected, we have to fetch value from "60" in "2019_20".

var taxSlab = {
    "2019_20" : {
        "60": [
        { "taxableAnnualIncome_from": 0, "taxableAnnualIncome_to": 250000, "taxPercentage": 0 },
        { "taxableAnnualIncome_from": 250000, "taxableAnnualIncome_to": 500000, "taxPercentage": 5 },
        { "taxableAnnualIncome_from": 500000, "taxableAnnualIncome_to": 100000, "taxPercentage": 10 },
        { "taxableAnnualIncome_from": 100000, "taxableAnnualIncome_to": 1000000, "taxPercentage": 20 },
                ],

        "80": [
        { "taxableAnnualIncome_from": 0, "taxableAnnualIncome_to": 250000, "taxPercentage": 0 },
        { "taxableAnnualIncome_from": 250000, "taxableAnnualIncome_to": 500000, "taxPercentage": 5 },
        { "taxableAnnualIncome_from": 500000, "taxableAnnualIncome_to": 100000, "taxPercentage": 10 },
        { "taxableAnnualIncome_from": 100000, "taxableAnnualIncome_to": 1000000, "taxPercentage": 20 },
                ] 
            },

    "2018_19" : {
        "60": [
        { "taxableAnnualIncome_from": 0, "taxableAnnualIncome_to": 250000, "taxPercentage": 0 },
        { "taxableAnnualIncome_from": 250000, "taxableAnnualIncome_to": 500000, "taxPercentage": 5 },
        { "taxableAnnualIncome_from": 500000, "taxableAnnualIncome_to": 100000, "taxPercentage": 10 },
        { "taxableAnnualIncome_from": 100000, "taxableAnnualIncome_to": 1000000, "taxPercentage": 20 },
                        ],

        "80": [
        { "taxableAnnualIncome_from": 0, "taxableAnnualIncome_to": 250000, "taxPercentage": 0 },
        { "taxableAnnualIncome_from": 250000, "taxableAnnualIncome_to": 500000, "taxPercentage": 5 },
        { "taxableAnnualIncome_from": 500000, "taxableAnnualIncome_to": 100000, "taxPercentage": 10 },
        { "taxableAnnualIncome_from": 100000, "taxableAnnualIncome_to": 1000000, "taxPercentage": 20 },
                        ] 
            },
}