samedi 9 mai 2015

Remove null elements from array jquery

I have my html like

  <input  type="text" class="form-control PaperSupply">` 
  <input  type="text" class="form-control PaperSupply">`
 <input  type="text" class="form-control PaperConsum">
 <input  type="text" class="form-control PC">

multiple inputs for same value papersupply and PaperConsum, in javascript i am creating an array for same value using map function like this

 var paperSupply = $('.PaperSupply').map(function(){return $(this).val();}).get(); 
 var PaperConsum= $('.PaperConsum').map(function(){return $(this).val();}).get(); 

now in json i want if any element of these array is null remove that element from array.

for example:

{"paperSupply":["","2","3","","5"],"paperConsum":["1","","4","5","6"]}

if this is json from above code, then i want above json like this,

{"paperSupply":["2","3","5"],"paperConsum":["","4","6"]}

Aucun commentaire:

Enregistrer un commentaire