0

My aim is to add a JSON object based on certain conditions to an array which is then to be used to construct a WINJSList. I'm really struggling with accessing the elements of the list OR array after I have used the array.push method. I wanted to access these elements to ensure I am doing the addition right. Any help would be greatly appreciated. I have the following code

    var names_Array = new Array;

                   var names_List = new WinJS.Binding.List(names_Array);

                    if (condition) {

                        if (condition) {
                            names_List.push({ name: "Joe Dowling", image: "image/Joe Dowling.png", ClientID: "1234" });
                        }
                        else if (condition) {
                            names_List.push({ name: "Esteban Flamenco ", image: "image/Esteban Flamenco.png", ClientID: "6666" });
                        }
                        else if (condition) {
                            names_List.push({ name: "Plain Jane ", image: "image/Plain Jane.png", ClientID: "0000" });
                        }

console.log(names_Array);
console.log(names_Array[0]);
console.log(names_List);
console.log(names_List[0]);

I also tried:

var names_Array = new Array; if (condition) {

                    if (condition) {
                        names_Array.push({ name: "Joe Dowling", image: "image/Joe Dowling.png", ClientID: "1234" });
                    }
                    else if (condition) {
                        names_Array.push({ name: "Esteban Flamenco ", image: "image/Esteban Flamenco.png", ClientID: "6666" });
                    }
                    else if (condition) {
                        names_Array.push({ name: "Plain Jane ", image: "image/Plain Jane.png", ClientID: "0000" });
                    }
var names_List = new WinJS.Binding.List(names_Array);

In the console I either get undefined or [object object]

1 Answer 1

1

I think you should just declare your names_Array like so:

var names_Array = [];

Also, using a switch statement would help to clear some confusion, I don't think there is a closing brace for the first if statement (from my observation)

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

1 Comment

@ Samuel Monday I had tried that way of declaring the array too but it didn't work. I actually got it working when I included the script in the html in script tags instead of saying the script source was another file. So, something weird was going on there. Thanks!

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.