I was trying to follow this  but I can't get it.  My data comes from this JSON: The green boxes show the values arrays and objets that I need to use.    So I need to find the object inside the array "options" which has the id == 233 and then return it's "value", I'm trying to do it with this function:  function getReqVal(val) {         for (var item in datos_puros[0].campos[0].campos[0].options) {             if(item.id == val) {                return item.value;             }         }     }   I'm bringin the val like this:  getReqVal(datos_puros[0].campos[0].campos[0].value[0]) //console.log(datos_puros[0].campos[0].campos[0].value[0]) --&gt; 233, it works   (datos_puros comes from an previous ajax call)  datos_puros = obj.estructura;   but I can't see where's my error. Please help  This is was I'm trying to do:
5927
I've been told not to use for...in with arrays in JavaScript. Why not?
17923
I have an array in the form of 'int[][]' that represents the co-ordinates of a small grid. Each co-ordinate has been assigned its own value. eg array[0][4] = 28......  I have two questions. Firstly, how do I iterate through all the stored values. Secondly, I want to be able to input a value and have its specific co-ordinates in the grid returned. What would be the best way to approach this?  Thank you for any help!
87459
Basically I have a setup like the following:  Array (  [0] =&gt; Array ( [0] =&gt; stdClass Object ( [nid] =&gt; 1 [title] =&gt; title1 [uid] =&gt; 1 [parent] =&gt; 0 [weight] =&gt; -15 [name] =&gt; name1 [value] =&gt; 0 )                [1] =&gt; stdClass Object ( [nid] =&gt; 2 [title] =&gt; title2 [uid] =&gt; 1 [parent] =&gt; 0 [weight] =&gt; -7 [name] =&gt; name2 [value] =&gt; 100 )                [2] =&gt; stdClass Object ( [nid] =&gt; 3 [title] =&gt; title3 [uid] =&gt; 2 [parent] =&gt; 0 [weight] =&gt; -1 [name] =&gt; name3 [value] =&gt; 0 )                [3] =&gt; stdClass Object ( [nid] =&gt; 4 [title] =&gt; title4 [uid] =&gt; 2 [parent] =&gt; 0 [weight] =&gt; 1 [name] =&gt; name4 [value] =&gt; 80 )               )   )   What I need is a way to sort all the arrays inside the parent array by the [value] key in the Object. I've been trying for about 2 days now with usort and different methods but I just can't seem to get my head around it. The [value] key will range anywhere from 0 to 100 and I need all of the arrays sorted in decreasing order (IE: 100 down to 0).
91152
I have a small requirement where in i need to remove the duplicate values from the array that i am getting.  Overview In the below code, what i am trying to do is to get top 1000 employee names(Should Cost Modeler People Picker Field) through REST API from List A and appending those values in LIST B Drop down. But as i get all the names through REST API there are many duplicate values in the array.   What i would like to do is to remove the duplicate values and then append the values to drop down.  //Get the employee names  function getAllEmployeeNames(){ var results; $.ajax({     url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('Should Cost Projects')/items?$select=Should_x0020_Cost_x0020_Modeler/Title&amp;$expand=Should_x0020_Cost_x0020_Modeler/Id&amp;$top=500",     type: "GET",     async:false,     headers: {         "Accept": "application/json;odata=verbose",     },     success: function (data) {         if(data.d.results.length&gt;0){             results=data.d.results;         }     },     error: function (data) {     //alert("Error");     } }); return results;   }   // To Append the Employee Name to drop down on form load.  var employeeName=$("input[title^='Employee Name']").val(); $("input[title^='Employee Name']").hide(); $("input[title^='Employee Name']").after("&lt;select id='EmployeeField' class='ms-RadioText'&gt;&lt;option value=''&gt;&lt;/option&gt;&lt;/select&gt;"); $("input[title^='Project Name']").hide(); $("input[title^='Project Name']").after("&lt;select id='ProjectField' class='ms-RadioText'&gt;&lt;option value=''&gt;&lt;/option&gt;&lt;/select&gt;"); var allEmployeeNames=getAllEmployeeNames(); console.log(allEmployeeNames);       $.each(allEmployeeNames,function(i,employee){     $.each(employee.Should_x0020_Cost_x0020_Modeler.results,function(j,item){         if(employeeName==item.Title){             $("#EmployeeField").append("&lt;option selected='selected' value='"+item.Title+"'&gt;"+item.Title+"&lt;/option&gt;");         }else{             if(item.Title!=undefined){                 $("#EmployeeField").append("&lt;option value='"+item.Title+"'&gt;"+item.Title+"&lt;/option&gt;");             }                    }        });          });   // the code that i am using to remove duplicates but it is not working.  $(allEmployeeNames).each(function() {     $(this).siblings('[value="'+ $(this).val() +'"]').remove(); });     Please help me solve this problem.  Thanks
107220
I have a map. the string is the label of a field of an object and the integer is the value that must go into this field of that object. But i don't know how to retrieve the API name of those fields from their labels. Please help!  Thanks in advance!
24499
I'm trying to parse some JSON using the JSon.Net library.  The documentation seems a little sparse and I'm confused as to how to accomplish what I need.  Here is the format for the JSON I need to parse through.  {     "displayFieldName" : "OBJECT_NAME",      "fieldAliases" : {         "OBJECT_NAME" : "OBJECT_NAME",          "OBJECT_TYPE" : "OBJECT_TYPE"     },      "positionType" : "point",      "reference" : {         "id" : 1111     },      "objects" : [ {         "attributes" : {             "OBJECT_NAME" : "test name",              "OBJECT_TYPE" : "test type"         },          "position" : {             "x" : 5,              "y" : 7         }     } ] }   The only data I really need from this is the stuff in the objects array.  Is it possible for me to parse through that with something like the JSonTextReader and just pull out the things I want, like OBJECT_TYPE and the x and y position?  I can't seem to get JSonTextReader to work the way I want it to and I find little to no examples of usage for it.   It seems like serializing first then using LINQ with my object would be ideal and every example I find discusses serializing the JSON first, but I'm not sure how I would build an object for this structure.  Particularly the objects array which would need to be something like a list of Pairs of attribute and position objects.  I have no idea how I would code my object so JSon.Net would know how to serialize that.  I thought I could write my own simple parser to just pull out everything I need into an attributes object that I created, but I'm having little luck.    Hopefully this all makes sense, any ideas?
82914
I have some dynamic SOQL code in which I'd like to identify whether a method argument is a collection or a single value:  SObject[] query(SObjectType sobType, String field, Object data) {     // Want to know if data is a collection e.g. set or list     // that requires an "in" or a single value that requires     // an "=" in the query. (May also need to use separate bind variables.) }   I note that the sort of check shown immediately below seems to require an exact match for the type of the collection (Id in this case to return true) which is not what I want:  Object o = new Set&lt;Id&gt;(); System.debug(o instanceof Set&lt;Id&gt;);   Is there a simple way to make this determination?  (Yes there are various other ways to code this; checking first to see if there is a direct solution.)  PS  Looks like great caution is needed when using .
13369
I have an Object[] array, and I am trying to find the ones that are primitives. I've tried to use Class.isPrimitive(), but it seems I'm doing something wrong:  int i = 3; Object o = i;  System.out.println(o.getClass().getName() + ", " +                    o.getClass().isPrimitive());   prints java.lang.Integer, false.  Is there a right way or some alternative?
26027
How do I append an object (such as a string or number) to an array in JavaScript?
118759
Question  I'm writing some code that needs to be able to get the values of the parameters from the method that called into the class. I know how to get all the way to the ParameterInfo[] array, but I don't know how to then get the values. Is this even possible?  If it is, I think it has something to do with using the MethodBody property from the MethodInfo object, which allows you to inspect the IL stream, including properties, but I don't know how to do it, and I haven't found applicable code on Google.  Code  // Finds calling method from class that called into this one public class SomeClass {     public static void FindMethod()     {         for (int i = 1; i &lt; frameCount; i++)         {             var frame = new StackFrame(i);             var methodInfo = frame.GetMethod();             if (methodInfo.DeclaringType != this.GetType())             {                 string methodName = frame.GetMethod().Name;                 var paramInfos = methodInfo.GetParameters();                  // Now what?? How do I get the values from the paramInfos                  break;             }             else if (i == frameCount - 1)             {                 throw new TransportException("Couldn't find method name");             }         }     } }
40506
I am writing a function that adds an ID number to an array and puts the array in the usermeta. $_GET['auction'] is the post_id.  Below is the function:  $reminders = get_user_meta( $current_user-&gt;ID, "reminders" ); print_r( $reminders ); if( in_array( $_GET['auction'], $reminders ) ) {     echo "Failed: Auction already in list"; } else {     array_push( $reminders, intval( $_GET['auction'] ) );     if ( update_user_meta( $current_user-&gt;ID, "reminders", $reminders ) ) {         echo "Success";     } else {         echo "Failed: Could not update user meta";     } } print_r( $reminders );   Here is the output after adding one auction:  Array ( )  Success Array ( [0] =&gt; 7 )    Here is the output after adding two auctions:  Array ( [0] =&gt; Array ( [0] =&gt; 7 ) )  Success Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 )   And here is the output after adding three auctions:  Array ( [0] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 ) )  Success Array ( [0] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 ) [1] =&gt; 0 )   Notice that adding a new element to the array using array_push works fine. But when the array is stored in the usermeta then retrieved again, the last element in the array has been put into an array of its own, creating an infinitely dimensional array. I'd prefer to keep this array one dimensional.  Is there a way I can run update_user_meta and get_user_meta without it changing the structure of my array?
13003
I'm having some trouble with plain old JavaScript (no frameworks) in referencing my object in a callback function.  function foo(id) {     this.dom = document.getElementById(id);     this.bar = 5;     var self = this;     this.dom.addEventListener("click", self.onclick, false); }  foo.prototype = {     onclick : function() {         this.bar = 7;     } };   Now when I create a new object (after the DOM has loaded, with a span#test)  var x = new foo('test');   The 'this' inside the onclick function points to the span#test and not the foo object.  How do I get a reference to my foo object inside the onclick function?
83765
This AJAX function gets called on a click:  $.ajax({             url: 'site/ajax.php',             data: {id: $('section#single article input:last-of-type').attr('value'), cote: 'like'}         }).done(function(html) {}   It passes the ID of the post (which is contained in a hidden input) for function get_post_meta() that is located in ajax.php. This is what AJAX.php looks like:  $cote = get_post_meta($_GET['id'], 'cote', true); if($_GET['cote'] == 'like') {     $newCote = $cote++;     update_post_meta($_GET['id'], 'cote', $newCote); } else {     $newCote = $cote--;     update_post_meta($_GET['id'], 'cote', $newCote); }   It is suppose to update the custom post's "cote" field, but the problem is that function get_post_meta() is undefined in ajax.php. This is the error message:  Fatal error: Call to undefined function get_post_meta() in /home2/electro/public_html/beta... on line 2
108547
I have a GeoJSON file that has fields of the days of the week like "Monday" with values 'Y' or 'N'. So I want to get today's day value, using something like  var theDayValue = 'feature.properties + day'   However this gives me a string. I want to get the value of   var theDayValue = feature.properties.Monday.   I plan on using this to show if open or closed in Leaflet by symbol color.
699
I am trying to return an array Data Member from one smaller 2D Array Object, and trying to insert the array into a larger 2D array object. But when attempting this, I came into two problems.  First problem is that I want to return the name of the 2D array, but I do not know how to properly syntax to return 2D Array name.  This is what my 2D Array data member looks like   private: int pieceArray[4][4]; // 2D Smaller Array   and I want to return this array into a function, but this one causes a compiler error:   int Piece::returnPiece() {     return pieceArray; //not vaild     // return the 2D array name }   I tired using this return type and it worked:   int Piece::returnPiece() {     return pieceArray[4][4]; }   But I am unsure if this is what I want, as I want to return the array and all of it's content.  The other problem is the InsertArray() function, where I would put the returnPiece() function in the InsertArray()'s argument.  The problem with the InsertArray() is the argument, heres the code for it:   void Grid::InsertArray( int arr[4][4] ) //Compiler accepts, but does not work {     for(int i = 0; i &lt x_ROWS ; ++i)     {          for (int j = 0; j &lt y_COLUMNS ; ++j)          {              squares[i][j] = arr[i][j];          }     } }   The problem with this is that it does not accept my returnPiece(), and if i remove the "[4][4]", my compiler does not accept.  Mostly all these are syntax errors, but how do I solve these problems?   Returning the whole pieceArray in returnPiece() The correct syntax for the argument in InsertArray() The argument of InsertArray() accepting the returnPiece()   These 3 are the major problems that I need help with, and had the same problem when I attempt to use the pointer pointer method. Does anyone know how to solve these 3 problems?
912
What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but . I've done things like obj = JSON.parse(JSON.stringify(o)); but question the efficiency.  I've also seen recursive copying functions with various flaws.  I'm surprised no canonical solution exists.
45659
After an AJAX request, sometimes my application may return an empty object, like:  var a = {};   How can I check whether that's the case?