數組之判斷取值,數組取值

來源:互聯網
上載者:User

數組之判斷取值,數組取值
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style>
        /*css reset開始*/
        body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,pre,form,input,textarea,th,td,select{margin: 0;padding: 0;font-size: 14px;font-family: "Microsoft Yahei";}
        input{width: 300px;height: 20px;vertical-align: middle;}
        li{list-style: none;vertical-align: top;}
        a{text-decoration: none;}
        img{border: none;vertical-align: top;}
        table{border-collapse: collapse;}
        textarea{resize: none;overflow: auto;}
        body{margin-top: 10px;}
        /*css reset結束*/
        form{width: 300px;}
        fieldset{margin: 20px;border: 2px dashed palevioletred;}
    </style>
    <script>
        window.onload = function(){
            var arr = ['100px', 'abc'-6, [], -98765, 34, -2, 0, '300', , function(){alert(1);}, null, document, [], true, '200px'-30,'23.45元', 5, Number('abc'), function(){ alert(3); }, 'xyz'-90 ];


            var oAllnum = document.getElementById('allNum');
            var oNum = document.getElementById('Num');
            var oMaxNum = document.getElementById('maxNum');
            var oNanLocation = document.getElementById('nanLocation');
            var arr1 = [];
            var arr2 = [];
            var arr3 = [];


//            1.數組裡所有的數字:↓↓
            for(var i=0;i<arr.length;i++){
                if(typeof arr[i] == 'number' && arr[i] === arr[i]){
                    arr1.push(arr[i]);
                }
            }
            oAllnum.value = arr1;


//            2.數組裡可以轉成數位:↓↓


            for(var i=0;i<arr.length;i++){
                if(isNaN(parseInt(arr[i])) == false){
                    arr2.push(arr[i]);
                }
            }
            oNum.value = arr2;


//            3.可以轉成數位再從中取最大值:↓↓
            var tmp =arr2;


            var max = tmp[0];


            for(var i=1;i<tmp.length;i++){


                if(max<tmp[i])
                {
                    max=tmp[i];
                }


            }
            oMaxNum.value=max;




//            4.NAN所在的位置:↓↓
            for(var i=0;i<arr.length;i++){
                if(typeof arr[i] == 'number' && isNaN(Number(arr[i]))){
                    arr3.push(i);
                }
            }
            oNanLocation.value = arr3;
        }
    </script>
</head>
<body>
    <form action="">
        <fieldset>
            <legend>輸出結果</legend>
            arr數組裡所有的數字:<input type="text" id="allNum"/><br/><br/>
            arr數組裡可以轉成數位: <input type="text" id="Num"/><br/><br/>
            把轉成數字以後的,再取最大值:<input type="text" id="maxNum"/><br/><br/>
            NaN所在的位置:<input type="text" id="nanLocation"/>
        </fieldset>
    </form>
</body>
</html>
PHP數組取值問題?

本人寫了個函數來尋找記錄,稍微做了通用性擴充,湊合著用吧,下面為測試代碼:

$a = array (
array('id' => 1, 'edition' => 'a'),
array('id' => 2, 'edition' => 'b'),
array('id' => 3, 'edition' => 'c'),
array('id' => 4, 'edition' => 'd'),
array('id' => 5, 'edition' => 'e'),
array('id' => 6, 'edition' => 'f'),
array('id' => 7, 'edition' => 'g'),
array('id' => 8, 'edition' => 'h'),
array('id' => 9, 'edition' => 'i'),
array('id' => 10, 'edition' => 'j'),
array('id' => 11, 'edition' => 'k'),
array('id' => 12, 'edition' => 'l'),
array('id' => 13, 'edition' => 'm'),
array('id' => 14, 'edition' => 'n'),
array('id' => 15, 'edition' => 'o'),
array('id' => 16, 'edition' => 'p'),
array('id' => 17, 'edition' => 'q'),
array('id' => 18, 'edition' => 'r'),
array('id' => 19, 'edition' => 's'),
array('id' => 20, 'edition' => 't')
);

/**
* 返回相鄰N條記錄,若返回空數組則說明沒有找到該記錄
* $records為記錄數組,$id為要尋找的記錄,$num為要返回的記錄數,預設為10
*/
function getRecords($r......餘下全文>>
 
EXCEL數組取值問題

C1到Z1是日期,這是什麼日期呀?這麼多日期?
不為空白則是什麼意思?說不清道不明,怎麼幫你解決?
發原檔案到sm100e@qq.com
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.