0
function checkmysize(){
var values = [];
var inputs = $('.size-col');
for(var i = 0; i < inputs.length; i++){
    values.push($(inputs[i]).val());
    alert(values);
}
}

my intention is count the same value in my array , i know i had to check the length and the value of each and push into a array , but how i count the same value in my array?

lets said if i got 3 s and 1 m , i want it to alert to like this s=3 , m=1, L=0. can any one give me a help ?

Demo

user3233074
  • 519
  • 4
  • 18
  • 1
    Possible duplicate of [Counting the occurrences of JavaScript array elements](http://stackoverflow.com/questions/5667888/counting-the-occurrences-of-javascript-array-elements) – ergonaut Nov 03 '15 at 17:12

1 Answers1

1

function checkmysize() {
  var values = [];
  var inputs = $('.size-col');
  for (var i = 0; i < inputs.length; i++) {
    values.push($(inputs[i]).val());
  }
  alert(values);
}

checkmysize();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <label>1.</label>
  <select class="size-col">
    <option value="s">S</option>
    <option value="m">M</option>
    <option selected value="l">L</option>
  </select>
</div>

<div>
  <label>2.</label>
  <select class="size-col">
    <option value="s">S</option>
    <option selected value="m">M</option>
    <option value="l">L</option>
  </select>
</div>

<div>
  <label>3.</label>
  <select class="size-col">
    <option value="s">S</option>
    <option selected value="m">M</option>
    <option value="l">L</option>
  </select>
</div>

<div>
  <label>4.</label>
  <select class="size-col">
    <option value="s">S</option>
    <option value="m">M</option>
    <option value="l">L</option>
  </select>
</div>
Lucky Chingi
  • 2,248
  • 1
  • 10
  • 15