0

My Existing Code and Explanation

Working Fine, But I want to Create a template like Its should read JSON Data that Having keys in any name, I am Always reading data from JSON object in 2nd Position

Now I read the JSON that passed in the argument (data) inside that using the for loop extract single object in group, after that get the data using key(Module_Name).. I know the key(Module_Name) is always present in second position only, Now its Working Fine with keyname rather i want to fetch the data using position, that also used as template in my other modules

/* render Screen Objects */
screenRenderer.displayScreens = function(data) 
{
     screenRenderer.renderLayout(function(cont, boo)
    {
        if (boo) 
        {

            for(i=0;i<data.length;i++)
            {

            var buttons = "<button class='screen_button'>"+data[i].Module_Name+"</button>";
                $("#screen-cont").append(buttons);

            }
        }
        else 
        {
            scr_cont.show();
        }
    })
}

This is My Requirement, kindly awaiting suggestions, answers.. Thanks in Advance

1 Answer 1

1

You can use the function Object.keys(obj) to get all keys of an object as array, which you can access with an Index and than use the String you get to access the property.

So it could look like this:

var obj = data[i];
var keys = Object.keys(obj);
var result = obj[keys[1]];

Hope this is what you want.

Sign up to request clarification or add additional context in comments.

3 Comments

This what exactly my requirement, Thank you so much bro
@KeerthiVasan you should accept answer if it helped you.
@Alexander Forelock sorry bro..I forgot to give the tick mark

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.