The jList property of the object is just a string, so you need to convert it to a Javascript object using JSON.parse().

// Dummy of your "data" variable
var data = {"jList":"[{\"added_by\":\"Ani\",\"description\":\"example description.\",\"start_date \":\"2014-10-10\",\"mark\":255,\"id\":975},{\"added_by\":\"Ani\",\"description \":\"example description..\",\"start_date\":\"2014-10-10\",\"mark\":255,\"id\":980 }]"};

var myList = JSON.parse(data.jList);
alert(myList.length); // Alerts "2"

Answer from Jan on Stack Overflow
Top answer
1 of 2
1

See this fiddle: https://jsfiddle.net/x983vvr6/2/

Essentially, assuming you have correctly set up the object you simply need to call

OrderStatusArray.length

And it will display the length of the array.

What length are you expecting? 3 is the correct answer and the answer which this fiddle shows.

Full code:

var OrderStatusArray = [{
"orderStatus": "S",
    "x_ExtnIsModifiable": "N",
    "grandTotal": "24",
    "orderId": "",
    "grandTotalCurrency": "USD",
    "placedDate": "2015-05-11T17:56:27.406Z",
    "x_ExtnIsModifiableUntil": "2012-07-24 23:59:00.0",
    "externalOrderID": "29001e"
  }, {
"orderStatus": "S",
    "x_ExtnIsModifiable": "N",
    "grandTotal": "23",
    "orderId": "",
    "grandTotalCurrency": "USD",
    "placedDate": "2015-04-11T17:56:27.406Z",
    "x_ExtnIsModifiableUntil": "2012-07-24 23:59:00.0",
    "externalOrderID": "29001d"
   }, {
"orderStatus": "S",
    "x_ExtnIsModifiable": "N",
    "grandTotal": "22",
    "orderId": "",
    "grandTotalCurrency": "USD",
    "placedDate": "2015-03-11T17:56:27.406Z",
    "x_ExtnIsModifiableUntil": "2012-07-24 23:59:00.0",
    "externalOrderID": "29001c"
     }];


console.log("Your order length array is: " + OrderStatusArray.length);
2 of 2
-1
var data = [  
   {  
      "orderStatus":"S",
      "x_ExtnIsModifiable":"N",
      "grandTotal":"24",
      "orderId":"",
      "grandTotalCurrency":"USD",
      "placedDate":"2015-05-11T17:56:27.406Z",
      "x_ExtnIsModifiableUntil":"2012-07-24 23:59:00.0",
      "externalOrderID":"29001e"
   },
   {  
      "orderStatus":"S",
      "x_ExtnIsModifiable":"N",
      "grandTotal":"23",
      "orderId":"",
      "grandTotalCurrency":"USD",
      "placedDate":"2015-04-11T17:56:27.406Z",
      "x_ExtnIsModifiableUntil":"2012-07-24 23:59:00.0",
      "externalOrderID":"29001d"
   },
   {  
      "orderStatus":"S",
      "x_ExtnIsModifiable":"N",
      "grandTotal":"22",
      "orderId":"",
      "grandTotalCurrency":"USD",
      "placedDate":"2015-03-11T17:56:27.406Z",
      "x_ExtnIsModifiableUntil":"2012-07-24 23:59:00.0",
      "externalOrderID":"29001c"
   }
];
console.log( data.length );

do you want this?

Discussions

node.js - Array length is not correct in javascript - Stack Overflow
It's not "the number of elements", as the name might suggest. When you iterate an array, either directly with for..of or map, or indirectly with e.g. JSON.stringify, JS just loops over all numbers from 0 to length - 1, and, if there's a property under this number, outputs/returns it. It doesn't look into other properties. ... The length property don't work ... More on stackoverflow.com
🌐 stackoverflow.com
jquery - Javascript : array.length returns undefined - Stack Overflow
An easy fix to this question is ... of your json file, and ending it with a ']'. This solved it for me. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s... Release notes and bug fixes ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Cannot print JSON array from ajax call using the array length - Stack Overflow
This is the Javascript with the Ajax call, everything is working fine, I don't need to parse JSon 'cause it already comes parsed and the object has an array inside. The problem is when I try to print the array output using the for loop into html, it does not recognize the "data.d.lenght" for ... More on stackoverflow.com
🌐 stackoverflow.com
Grabbing the length of an array in json object
Nothing wrong with using an if statement to check if the array exists. If there's only 2 possible options, you can do it in 1 line, using ternary if statement: let array1 = [1, 2, 3] let array2 = [4, 5, 6, 7, 8, 9, 10] const arrayLength = array1 ? array1.length : array2.length console.log(arrayLength) // displays 3 Explanation: Ternary operator checks if the condition array1 is a truthy value (not undefined, null, false), if so, return array1.length, else return array2.length More on reddit.com
🌐 r/learnjavascript
3
2
March 22, 2021
Top answer
1 of 3
2

.length is a special property in Javascript arrays, which is defined as "the biggest numeric index in the array plus one" (or 2^32-1, whatever comes first). It's not "the number of elements", as the name might suggest.

When you iterate an array, either directly with for..of or map, or indirectly with e.g. JSON.stringify, JS just loops over all numbers from 0 to length - 1, and, if there's a property under this number, outputs/returns it. It doesn't look into other properties.

2 of 3
0

The length property don't work as one will expect on arrays that are hashtables or associative arrays. This property only works as one will expect on numeric indexed arrays (and normalized, i.e, without holes). But there exists a way for get the length of an associative array, first you have to get the list of keys from the associative array using Object.keys(arr) and then you can use the length property over this list (that is a normalized indexed array). Like on the next example:

arr=[];
arr[0]={"zero": "apple"};
arr[1]={"one": "orange"};
arr["fancy"]="what?";

console.log(Object.keys(arr).length);

And about this next question:

not able to get all values while doing console.log(JSON.stringify(arr))

Your arr element don't have the correct format to be a JSON. If you want it to be a JSON check the syntax on the next example:

jsonObj = {};
jsonObj[0] = {"zero": "apple"};
jsonObj[1] = {"one": "orange"};
jsonObj["fancy"] = "what?";

console.log(Object.keys(jsonObj).length);
console.log(JSON.stringify(jsonObj));

🌐
Stack Overflow
stackoverflow.com › questions › 52521561 › cannot-print-json-array-from-ajax-call-using-the-array-length
javascript - Cannot print JSON array from ajax call using the array length - Stack Overflow
I don't know what else I can do besides getting a variable with the array size from codebehind but that is a last resort. Copy <script type="text/javascript"> function GetColaboradores() { var url = "GetColaboradoresWebService.asmx/GetColaboradores"; $("#UpdatePanel").html("<div style='text-align:center; background-color:yellow; border:1px solid red; padding:3px; width:200px'>Please Wait...</div>"); var request = $.ajax({ type: "POST", url: url, data: "{}", contentType: "application/json; charset-utf-8", dataType: "json" }); request.done(function (data) { var TableContent = "<table border='0'" + "<tr>" + "<td> Nome </td>" + "</tr>"; for (var i = 0; i > data.d.lenght; i++) { TableContent += "<tr>" + "<td>" + data.d[i].Nome + "</td>" "</tr>"; } TableContent += "</table>"; $("#UpdatePanel").html(TableContent); }); request.fail(function () { }); } </script>
🌐
Reddit
reddit.com › r/learnjavascript › grabbing the length of an array in json object
r/learnjavascript on Reddit: Grabbing the length of an array in json object
March 22, 2021 -

My question is pretty straight forward,

I am trying to grab the lenght of an array returned by my json. However, the array could be possibly two different names (for example orange or apple)

so how would I write code that would just grab the array length regardless of the array name

Find elsewhere
🌐
ServiceNow Community
servicenow.com › community › app-engine-forum › getting-the-value-and-length-of-an-array-in-json-format › td-p › 2807539
Solved: Getting the value and length of an array in JSON f... - ServiceNow Community
July 30, 2024 - Vishal Birajdar ServiceNow Developer I know one thing, and that is that I know nothing. - Socrates ... Have you tried using Object.keys(name of your array).length to get the length ? Refer https://linuxhint.com/dictionary-length-javascript/
🌐
Stack Overflow
stackoverflow.com › questions › 53576682 › arrays-in-arrays-length-always-is-0-json-not-working
javascript - Arrays in arrays, length always is 0, json not working - Stack Overflow
December 2, 2018 - I try to create arrays in arrays and then forward it to JSON. First problem, when i try to use a lista.length or something, console always return 0. I tried to overpass this problem and create ano...