1

I want like this:-

Array
    (
        [sys_dropdowns] => Array
            (
                [branchs] => Array
                    (
                        [branchs.branchs_id] => Array
                            (
                                [permission] => %BRANCHS_PRIVILEGE
                                [no_permission] => 
                                [sql_where_clause] => 
                            )
    
                    )
            )
    
        [sys_master_grid] => Array
            (
                [draft_voucher_list] => Array
                    (
                        [acc_voucher_main.branchs_id] => Array
                            (
                                [permission] => %BRANCHS_PRIVILEGE
                                [no_permission] => 
                                [sql_where_clause] => 
                            )
    
                    )
    
            )
    
        )
    
    )

I am trying this :-

var all_permission = []; 
    sql_data.forEach(function(val) {
        if (all_permission[val.event_ref] === undefined) all_permission[val.event_ref] = [];
        if (all_permission[val.event_ref][val.event_slug] === undefined) all_permission[val.event_ref][val.event_slug] = [];
        all_permission[val.event_ref][val.event_slug][val.event_slug_key] = {
            permission:val.permission,
            no_permission:val.no_permission,
            sql_where_clause:val.sql_where_clause
        }
    });

But when i return all_permission variable its send blank array but when i console all_permission its shows exactly what i want. if i push single value then also send perfect result but when i try to create multi then arise this issue. Please help how can i return multidimensional array?

1 Answer 1

1

You are messing between array and object. Try something like this

var all_permission = {}; 
sql_data.forEach(function(val) {
    if (type of all_permission[val.event_ref] === 'undefined') all_permission[val.event_ref] = {};
    if (typeof all_permission[val.event_ref][val.event_slug] === 'undefined') all_permission[val.event_ref][val.event_slug] = {};
    all_permission[val.event_ref][val.event_slug][val.event_slug_key] = {
        permission:val.permission,
        no_permission:val.no_permission,
        sql_where_clause:val.sql_where_clause
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Great!! Thanks bro @Foysal Nibir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.