Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd JSON object to multidimensional array in javascript
    primarykey
    data
    text
    <p>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 </p> <pre><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]); </code></pre> <p>I also tried: </p> <pre><code>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); </code></pre> <p>In the console I either get undefined or [object object]</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload