Solved

Javascript Push() and value access

Posted on 2014-02-26
5
435 Views
Last Modified: 2014-02-28
Hi,

Can someone check and see if the following javascript is correct?  I am trying to push values from a sharepoint list into a multidimensional array but I think I might be doing something wrong when I try to access.  I get an error due to the .each() and when I take it out, the error goes away.  The error says I'm missing a ")"

var anArray = new Array();


$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Analyst",
	CAMLViewFields: "<ViewFields><FieldRef Name='Title'></FieldRef></ViewFields>",
	CAMLQuery: "<Query><OrderBy><FieldRef Name='Title' /></OrderBy></Query>",
    completefunc: function (xData, Status) {
	//alert(xData.responseXML.xml);
      $(xData.responseXML).SPFilterNode("z:row").each(function() { 


			anArray.push({
				Analyst: $(this).attr("ows_Title"),
				Count:	 0
				});			
				


      });
     }
  }); 


   //Am I accessing the values to my array correctly
   $.each(anArray, function (index, value) {																													
        dataAn.addRow([anArray[index].Analyst, Number(anArray[index].Count]));
    }); 

Open in new window

0
Comment
Question by:Isaac
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:Sar1973
ID: 39891322
I think you're missing a parenthesis...try each(function()) and see http://www.w3schools.com/Php/func_array_each.asp
0
 
LVL 5

Author Comment

by:Isaac
ID: 39891685
I am using jquery not php
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39891798
Then you maybe have inserted } instead of }); at line 23.
0
 
LVL 5

Author Comment

by:Isaac
ID: 39891959
I'm using notepad and all of my braces and parenthesis have their open and close.

Is this right?
alert(anArray[x].Count);

What's the proper syntax to get the value of that kind of an array?
0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 500 total points
ID: 39892053
anArray[x] is the right syntax to get the x-element of the array, while anArray.length will return the number of elements in the array.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question