// Array is the simplest form of data structure to store collection of data
    // array: the simplest form of data structure
    let the_array1 = [0, 1.2, "a2rp", true, false, undefined, null];
    console.log(JSON.stringify(the_array1)); // [0, 1.2, 'a2rp', true, false, undefined, null]

    // length of array
    console.log("\n");
    let length = the_array1.length;
    console.log("length of array:",length);

    // array are capable of storing complex objects
    console.log("\n");
    let object_array = [
        {
            first_name: "Ashish",
            last_name: "Ranjan",
            year: 2022,
            complete_date: "April 04, 2022",
        },
        {
            subject_1: "Physics",
            subject_2: "Chemistry",
            subject_3: "Mathematics",
            subject_4: "Biology",
            subject_5: "Computer Science"

        }
    ];
    console.log(JSON.stringify(object_array)); 
    // [{"first_name":"Ashish","last_name":"Ranjan","year":2022,"complete_date":"April 04, 2022"},{"subject_1":"Physics","subject_2":"Chemistry","subject_3":"Mathematics","subject_4":"Biology","subject_5":"Computer Science"}]

    // Access an Array's Contents Using Bracket Notation
    let access_array = [1,2,3,4,true,"a2rp"];
    console.log(`value at third position in the array '${access_array}' is  access_array[2] = ${access_array[2]} `);

    // change value
    console.log("\n");
    console.log(`original array \naccess_array = ${access_array}`);
    access_array[2] = 99;
    console.log(`changing the value with \naccess_array[2] = 99 \ngives new array as \naccess array = ${access_array}`);

    // arrays are mutable
    // elements can be added or removed over time
    // to modify an array we use: Array.push() and Array.unshift()
    // push() adds element to end of the array
    // unshift() adds element to the beginning of the array
    console.log("\n");
    let array_1 = [1,2,3];
    console.log(`array_1 = ${array_1}`); 
    // array_1 = 1,2,3
    
    array_1.push(4);
    console.log(`after 'array_1.push(4)'\narray_1 = ${array_1}`); 
    // after 'array_1.push(4)'
    // array_1 = 1,2,3,4

    array_1.unshift(0);
    console.log(`after 'array_1.unshift(0)'\narray_1 = ${array_1}`); 
    // after 'array_1.unshift(0)'
    // array_1 = 0,1,2,3,4

    console.log("\n");
    // pop() and unsift()
    // pop: pop() removes an element from the end of an array
    // shift() removes an element from the beginning
    let array_2 = [0,1,2,3,4,5,6];
    console.log(`array_2 = ${array_2} length = ${array_2.length}`);
    // array_2 = 0,1,2,3,4,5,6 length = 7
    let pop_element = array_2.pop();
    console.log(`after "array_2.pop()"\narray_2 = ${array_2} length = ${array_2.length}`);
    // after "array_2.pop()"
    // array_2 = 0,1,2,3,4,5 length = 6
    let shift_element = array_2.shift();
    console.log(`after "array_2.shift()"\narray_2 = ${array_2} length = ${array_2.length}`);
    // after "array_2.shift()"
    // array_2 = 1,2,3,4,5 length = 5

    console.log("\n");
    // splice(): remove any number of consecutive elements from anywhere in an array.
    // array.splice(index, howmany, item1, ....., itemX)
    // index	Required: The position to add/remove items. Negative value defines the position from the end of the array.
    // howmany	Optional: Number of items to be removed.
    // item1, ..., itemX	Optional.New elements(s) to be added.
    let array_3 = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    console.log(`array_3 = ${array_3}`);
    // array_3 = Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
    let splice_new_array = array_3.splice(2,2,"Mangalwar", "Boodhwar");
    console.log(`after "array_3.splice(2,2,"Mangalwar", "Boodhwar")\nsplice_new_array = ${splice_new_array}\narray_3 = ${array_3}" `);
    // after "array_3.splice(2,2,"Mangalwar", "Boodhwar")
    // splice_new_array = Tuesday,Wednesday
    // array_3 = Sunday,Monday,Mangalwar,Boodhwar,Thursday,Friday,Saturday" 

    console.log("\n");
    // slice() copies or extracts a given number of elements to a new array, leaving the array it is called upon untouched
    let array_4 = [0,1,2,3,4,5];
    let sliced_array = array_4.slice(2,4);
    console.log(`array_4 = ${array_4}`);
    // array_4 = 0,1,2,3,4,5
    console.log(`sliced_array = slice(2,4) gives\nsliced_array = ${sliced_array}\narray_4 = ${array_4}`);
    // sliced_array = slice(2,4) gives
    // sliced_array = 2,3
    // array_4 = 0,1,2,3,4,5

    console.log("\n");
    // simple log vs JSON.stringify
    let array_5 = [true,false,undefined,false,null];
    console.log(`array_5 = ${array_5}`);
    // array_5 = true,false,,false,
    console.log(`array_5 = ${JSON.stringify(array_5)}`);
    // array_5 = [true,false,null,false,null]
    let array_6 = [-1,0,1];

    console.log("\n");
    // spread operator
    let array_7 = [-3,-2,-1,0,1,2,3];
    let new_array_7 = [...array_7];
    console.log(`array_7 = ${array_7}\nnew_array_7 = [...array_7] gives\nnew_array_7 = ${new_array_7}`);
    // array_7 = -3,-2,-1,0,1,2,3
    // new_array_7 = [...array_7] gives
    // new_array_7 = -3,-2,-1,0,1,2,3
    let new_array1_7 = ["a","b","c",...array_7,"d","e","f"];
    console.log(`array_7 = ${array_7}\nlet new_array1_7 = ["a","b","c",...array_7,"d","e","f"] gives\nnew_array_7 = ${new_array1_7}`);
    // array_7 = -3,-2,-1,0,1,2,3
    // let new_array1_7 = [3,...array_7] gives
    // new_array_7 = a,b,c,-3,-2,-1,0,1,2,3,d,e,f

    console.log("\n");
    // indexOf(): allows us to quickly and easily check for the presence of an element on an array
    let array_8 = [0,1,2,"a2rp",false];
    console.log(`array_8 = ${array_8}\nindex of 1 = ${array_8.indexOf(1)}\nindex of "a2rp" = ${array_8.indexOf("a2rp")}\nindex of "false" = ${array_8.indexOf(false)}\nindex of "true" = ${array_8.indexOf(true)}`);
    // array_8 = 0,1,2,a2rp,false
    // index of 1 = 1
    // index of "a2rp" = 3
    // index of "false" = 4
    // index of "true" = -1

    console.log("\n");
    // iterate array with for loop
    let array_9 = [1,2,3];
    let total_items_2add = 5;
    console.log(`array_9 = ${array_9}`);
    // array_9 = 1,2,3
    // add elements to array
    for (let i=0; i<total_items_2add; ++i) {
        array_9.push(Math.floor(Math.random()*100));
    }
    console.log(`after adding elements\narray_9 = ${array_9}`);
    // after adding elements
    // array_9 = 1,2,3,61,86,69,76,38

    console.log("\n");
    // multi dimensional array
    let array_10 = [
        [1,2,3],
        [
            {
                first_name: "Ashish",
                last_name: "Ranjan"
            }
        ],
        {
            day: "Monday",
            year: 2022
        },
        [
            [
                [45,"deeply nested"]
            ]
        ]
    ];
    console.log(`array_10 = ${array_10}`);
    // array_10 = 1,2,3,[object Object],[object Object]
    console.log(`array_10 = ${JSON.stringify(array_10)}`);
    // array_10 = [[1,2,3],[{"first_name":"Ashish","last_name":"Ranjan"}],{"day":"Monday","year":2022}]
    console.log(`array_10[3][0][0] = ${array_10[3][0][0]}`);
    // array_10[3][0][0] = 45,deeply nested
    console.log(`array_10[3][0][0][0] = ${array_10[3][0][0][0]}`);
    // array_10[3][0][0][0] = 45
    console.log(`array_10[3][0][0][1] = ${array_10[3][0][0][1]}`);
    // array_10[3][0][0][1] = deeply nested

    console.log("\n");
    // key value pairs in javascript objects
    let year = 2022;
    let object_1 = {
        first_name: "Ashish",
        last_name: "Ranjan",
        current_year: year
    };
    console.log(`object_1 = ${JSON.stringify(object_1)}`);
    // object_1 = {"first_name":"Ashish","last_name":"Ranjan","current_year":2022}
    object_1.key_1 = "key value";
    console.log(`after object_1.key_1 = "key value" object_1 = ${JSON.stringify(object_1)}`);
    // after object_1.key_1 = "key value" object_1 = {"first_name":"Ashish","last_name":"Ranjan","current_year":2022,"key_1":"key value"}
    // Bracket notation is required if our property has a space in it or if we want to use a variable to name the property
    object_1["current month"] = "April";
    console.log(`after object_1["current month"] = "April" object_1 = ${JSON.stringify(object_1)}`);
    // after object_1["current month"] = "April" object_1 = {"first_name":"Ashish","last_name":"Ranjan","current_year":2022,"key_1":"key value","current month":"April"}
    let date_time = "date and time";
    object_1[date_time] = "April 05, 2022 1238hrs";
    console.log(`object 1 = ${JSON.stringify(object_1)}`);
    // object 1 = {"first_name":"Ashish","last_name":"Ranjan","current_year":2022,"key_1":"key value","current month":"April","date and time":"April 05, 2022 1238hrs"}

    console.log("\n");
    // objects nested within objects
    let object_2 = {
        id: 1234567890,
        name: {
            first_name: "Ashish",
            last_name: "Ranjan"
        },
        full_date: {
            day: "Monday",
            date: 4,
            year: 2022,
            time: {
                hours: 12,
                minutes: 48,
                hour_format: {
                    format_1: "12 hours format",
                    format_2: "24 hours format"
                }
            }
        }
    };
    console.log(`object_2 = ${JSON.stringify(object_2)}`);
    // {"first_name":"Ashish","last_name":"Ranjan"},"full_date":{"day":"Monday","date":4,"year":2022,"time":{"hours":12,"minutes":48,"hour_format":{"format_1":"12 hours format","format_2":"24 hours format"}}}}
    let object_2_deep_value = object_2.full_date.time.hour_format.format_2;
    console.log(`object_2_deep_value = ${object_2_deep_value}`);
    // object_2_deep_value = 24 hours format
    // edit value
    let object_value_chaged = object_2.full_date.time.hour_format.format_2 = "changed format value";
    console.log(`object value changed\nobject_2 = ${JSON.stringify(object_2)}`);
    // object value changed
    // object_2 = {"id":1234567890,"name":{"first_name":"Ashish","last_name":"Ranjan"},"full_date":{"day":"Monday","date":4,"year":2022,"time":{"hours":12,"minutes":48,"hour_format":{"format_1":"12 hours format","format_2":"changed format value"}}}}

    console.log("\n");
    // delete object properties
    let object_4 = {
        first_name: "Ashish",
        last_name: "Ranjan",
        full_name: "Ashish Ranjan"
    };
    console.log(`object_4 = ${JSON.stringify(object_4)}`);
    // object_4 = {"first_name":"Ashish","last_name":"Ranjan","full_name":"Ashish Ranjan"}
    delete object_4.full_name;
    console.log(`after delete: object_4 = ${JSON.stringify(object_4)}`);
    // after delete: object_4 = {"first_name":"Ashish","last_name":"Ranjan"}

    console.log("\n");
    // check has object property
    let object_5 = {
        first_name: "Ashish",
        last_name: "Ranjan"
    };
    console.log(`has object_5 property "first_name"??? ${object_5.hasOwnProperty("first_name")}`);
    // has object_5 property "first_name"??? true

    console.log("\n");
    // Iterate Through the Keys of an Object
    let object_6 = {
        first_name: "Ashish",
        last_name: "Ranjan",
        full_name: "Ashish Ranjan",
        date: 4,
        day: "Monday",
        month: "April",
        full_date: "1404hrs April 04, 2022",
    };
    for (let key in object_6) {
        console.log(`key  = ${key}`);
    }
    // key  = first_name
    // key  = last_name
    // key  = full_name
    // key  = date
    // key  = day
    // key  = month
    // key  = full_date

    console.log("\n");
    // repeated keys
    let object_7 = {
        key_1: "value 1",
        key_1: "value 2",
        key_1: "value 3",
    };
    console.log(object_7);
    // {key_1: 'value 3'}

    console.log("\n");
    // store object keys into arrays
    let object_8 = {
        key_1: "value 1",
        key_2: "value 2",
        key_3: "value 3",
    };
    let all_object_keys = Object.keys(object_8);
    console.log(`keys stored int the array are: ${all_object_keys}`);
    // keys stored int the array are: key_1,key_2,key_3


    console.log("\n");
    // modify an stored in an object
    let object_9 = {
        first_name: "Ashish",
        last_name: "Ranjan",
        full_date: ["April", 4, 2021],
    };
    console.log(`object_9 = ${JSON.stringify(object_9)}`);
    // object_9 = {"first_name":"Ashish","last_name":"Ranjan","full_date":["April",4,2021]}

    object_9.full_date[2] = 2022;
    console.log(`object_9 = ${JSON.stringify(object_9)}`);
    // object_9 = {"first_name":"Ashish","last_name":"Ranjan","full_date":["April",4,2022]}