Q:

Get count of arrays returned in $.each

Seems like a simple question but can't find a result anywhere in JQuery help or on SO. How do I get the count of the number of arrays returned from JSON array. cust_id may return 2 arrays or as many as 10.
$.each(data, function() {
       if (this.cust_id == selectedProductAutonum) {
         invoices = this;                                         
         return true;
         alert(this.length);
       }
 });

example JSON:
var myjson = [{
    "autonum": "20",
    "date": "2017-03-22",
    "customer": "Jeffs Music\r\n",
    "address": "Montgomery Station",
    "invoice": "20160929",
    "sales": "2416.00",
    "paid": "1000.00",
    "owed": "1416.00",
    "tax": "0.00",
    "misc": "2017-03-22 19:51:00",
    "cust_id": "15",
    "product": "Labor",
    "description": "Complete Install Labor only (DVR configuration, Install, Pow",
    "cost": "2150.00",
    "quantity": "1",
    "price": "2150.00",
    "timestamp": "2017-03-22 19:51:00"
}, {
    "autonum": "21",
    "date": "2017-03-22",
    "customer": "Jeffs Music\r\n",
    "address": "Montgomery Station",
    "invoice": "20160929",
    "sales": "2416.00",
    "paid": "1000.00",
    "owed": "1416.00",
    "tax": "0.00",
    "misc": "2017-03-22 19:51:00",
    "cust_id": "15",
    "product": "Home Depot",
    "description": "Home Depot Supplies for Shelf/mounts/braces/paint.",
    "cost": "128.50",
    "quantity": "1",
    "price": "128.50",
    "timestamp": "2017-03-22 19:51:00"
}, {
    "autonum": "22",
    "date": "2017-03-22",
    "customer": "Mikes Music\r\n",
    "address": "Montgomery Station",
    "invoice": "20160929",
    "sales": "2416.00",
    "paid": "1000.00",
    "owed": "1416.00",
    "tax": "0.00",
    "misc": "2017-03-22 19:51:00",
    "cust_id": "15",
    "product": "Cables",
    "description": "Cables and Connectors / power pigtails",
    "cost": "43.85",
    "quantity": "1",
    "price": "43.85",
    "timestamp": "2017-03-22 19:51:00"
}, {
    "autonum": "23",
    "date": "2017-03-22",
    "customer": "Jeffs Music\r\n",
    "address": "Montgomery Station",
    "invoice": "20160929",
    "sales": "2416.00",
    "paid": "1000.00",
    "owed": "1416.00",
    "tax": "0.00",
    "misc": "2017-03-22 19:51:00",
    "cust_id": "10",
    "product": "Cables",
    "description": "Cables and connectors / hardware used in November 2016",
    "cost": "45.55",
    "quantity": "1",
    "price": "45.55",
    "timestamp": "2017-03-22 19:51:00"
}, {
    "autonum": "24",
    "date": "2017-03-22",
    "customer": "Jeffs Music\r\n",
    "address": "Montgomery Station",
    "invoice": "20160929",
    "sales": "2416.00",
    "paid": "1000.00",
    "owed": "1416.00",
    "tax": "0.00",
    "misc": "2017-03-22 19:51:00",
    "cust_id": "10",
    "product": "Cables",
    "description": "Extension power supply cables",
    "cost": "43.12",
    "quantity": "1",
    "price": "43.12",
    "timestamp": "2017-03-22 19:51:00"
}]

A:

You can use the function filter to get a array of objects which have cust_id === "10".

var myjson = [{    "autonum": "20",    "date": "2017-03-22",    "customer": "Jeffs Music\r\n",    "address": "Montgomery Station",    "invoice": "20160929",    "sales": "2416.00",    "paid": "1000.00",    "owed": "1416.00",    "tax": "0.00",    "misc": "2017-03-22 19:51:00",    "cust_id": "15",    "product": "Labor",    "description": "Complete Install Labor only (DVR configuration, Install, Pow",    "cost": "2150.00",    "quantity": "1",    "price": "2150.00",    "timestamp": "2017-03-22 19:51:00"}, {    "autonum": "21",    "date": "2017-03-22",    "customer": "Jeffs Music\r\n",    "address": "Montgomery Station",    "invoice": "20160929",    "sales": "2416.00",    "paid": "1000.00",    "owed": "1416.00",    "tax": "0.00",    "misc": "2017-03-22 19:51:00",    "cust_id": "15",    "product": "Home Depot",    "description": "Home Depot Supplies for Shelf/mounts/braces/paint.",    "cost": "128.50",    "quantity": "1",    "price": "128.50",    "timestamp": "2017-03-22 19:51:00"}, {    "autonum": "22",    "date": "2017-03-22",    "customer": "Mikes Music\r\n",    "address": "Montgomery Station",    "invoice": "20160929",    "sales": "2416.00",    "paid": "1000.00",    "owed": "1416.00",    "tax": "0.00",    "misc": "2017-03-22 19:51:00",    "cust_id": "15",    "product": "Cables",    "description": "Cables and Connectors / power pigtails",    "cost": "43.85",    "quantity": "1",    "price": "43.85",    "timestamp": "2017-03-22 19:51:00"}, {    "autonum": "23",    "date": "2017-03-22",    "customer": "Jeffs Music\r\n",    "address": "Montgomery Station",    "invoice": "20160929",    "sales": "2416.00",    "paid": "1000.00",    "owed": "1416.00",    "tax": "0.00",    "misc": "2017-03-22 19:51:00",    "cust_id": "10",    "product": "Cables",    "description": "Cables and connectors / hardware used in November 2016",    "cost": "45.55",    "quantity": "1",    "price": "45.55",    "timestamp": "2017-03-22 19:51:00"}, {    "autonum": "24",    "date": "2017-03-22",    "customer": "Jeffs Music\r\n",    "address": "Montgomery Station",    "invoice": "20160929",    "sales": "2416.00",    "paid": "1000.00",    "owed": "1416.00",    "tax": "0.00",    "misc": "2017-03-22 19:51:00",    "cust_id": "10",    "product": "Cables",    "description": "Extension power supply cables",    "cost": "43.12",    "quantity": "1",    "price": "43.12",    "timestamp": "2017-03-22 19:51:00"}],
    selectedProductAutonum = "10",
    result = myjson.filter(({cust_id}) => cust_id === selectedProductAutonum);
    
console.log("Length:", result.length);

selectedProductAutonum = "15";
result = myjson.filter(({cust_id}) => cust_id === selectedProductAutonum);

console.log("Length:", result.length);
.as-console-wrapper { max-height: 100% !important; top: 0; }

