1

hi i would like to know how to read every array item using jQuery. I'm getting some li values, push them in an array and then sort them using a bubble sort function

function sortSizes(sizesArr) {
    for (var i = 0; i < sizesArr.length; i ++) {
        for (var j = i + 1; j < sizesArr.length; j ++) {
          ....
          ...
        }
    }
}
sortSizes(myArray)

all what i need then is to get every item in array and added to an href attribute

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
User1979
  • 817
  • 3
  • 13
  • 23

1 Answers1

3

You can use $.each (just a sample example)-

var arr = [
   'one',
   'two',
   'three',
   'four',
   'five'
];
$.each(arr, function (index, value) {
 $('#mydiv').append(value+"<br>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id = "mydiv"></div>

Or forEach():-

var arr = [
   'one',
   'two',
   'three',
   'four',
   'five'
];
arr.forEach(function(value,index){
 $('#mydiv').append(value+"<br>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id = "mydiv"></div>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98