1. var arr = [
    2. {name:"李四",age:18},
    3. {name:"王四",age:20},
    4. {name:"zs",age:8},
    5. {name:"cs",age:16}
    6. ]
    7. var newValue = []
    8. for(var i=0;i<arr.length;i++){
    9. if(arr[i].age>16){
    10. newValue.push(arr[i])
    11. }
    12. }
    13. console.log(newValue);
    14. 判断数组中对象的age属性,如果大于16就将其添加到newValue数组中
    1. var arr = [1,2,3,4,5,6,7,8,9]
    2. var test = []
    3. for(var i=0;i<arr.length;i += 3){
    4. test.push(arr.slice(i,i+3))
    5. }
    6. console.log(test);
    7. 将其三个数一组,截取成三行三列的二维数组
    1. 查询数组中的最小值
    2. 1
    3. var arr = [4,6,18,1]
    4. var min = arr[0]
    5. console.log(arr.length);
    6. for(var i=1;i<arr.length;i++){
    7. if(min>arr[i]){
    8. min = arr[i]
    9. }
    10. }
    11. console.log(min);
    12. 2
    13. var arr = [4,6,18,1]
    14. var min = arr[0]
    15. for(var i=1;i<arr.length;i++){
    16. min = Math.min(arr[0],arr[i])
    17. }
    18. 3
    19. var arr = [4,6,18,1]
    20. var min
    21. for(var i=0;i<arr.length-1;i++){
    22. for(var j=i+1;j<arr.length;j++){
    23. if(arr[i]<arr[j]){
    24. min = arr[i]
    25. }else{
    26. min = arr[j]
    27. }
    28. min = Math.min(arr[i],arr[j])
    29. }
    30. }
    1. var arr = [
    2. {name:'lisi',age:'12px'},
    3. {name:'wangwu',age:'13px'},
    4. {name:'zhangsan',age:'14px'}
    5. ]
    6. for(var i=0;i<arr.length;i++){
    7. var age = parseInt(arr[i].age)*2
    8. arr[i].age = age
    9. arr[i].like = true
    10. if(arr[i].age<26){
    11. arr[i].like = false
    12. }
    13. }
    14. console.log(arr);
    15. 将数组arr中的对象属性age的值转换为数字
    16. 并在age大于24的对象中添加like=true属性
    1. var searchs = [
    2. {
    3. spell:'A',
    4. city:[
    5. {name:'阿里',id:1001},
    6. {name:'阿拉',id:1001},
    7. {name:'阿克',id:1001}
    8. ]
    9. },{
    10. spell:'T',
    11. city:[
    12. {name:'天下',id:2001},
    13. {name:'天天',id:2002},
    14. {name:'天里',id:2003}
    15. ]
    16. }
    17. ]
    18. var input = document.getElementById('input')
    19. var arr = []
    20. var kw;
    21. input.onkeydown = function(event){
    22. if(event.keyCode === 13){
    23. if(this.value != ""){
    24. kw = this.value
    25. addCity(kw)
    26. console.log(arr);
    27. this.value = ""
    28. kw = this.value
    29. arr = []
    30. }
    31. }
    32. }
    33. function addCity(keyword){
    34. for(var i=0;i<searchs.length;i++){
    35. var citys = searchs[i].city
    36. for(var j=0;j<citys.length;j++){
    37. console.log(citys[j]);
    38. if(citys[j].name.includes(keyword)){
    39. arr.push(citys[j])
    40. }
    41. }
    42. }
    43. }
    44. 在输入框中输入,获取到输入框中的value值,并通过数组的include方法判断这个值是否在数组的对象的那么属性的属性值中,
    45. 在的话,将这个对象保存到另一个数组中,输出